Google Android Drive api sign in fails on installed version

折月煮酒 提交于 2019-12-07 15:46:51

问题


I have developed an android application that uses the GoogleDrive api,

When under debug or running the debug version, the application works fine, and correctly authenticates to the attached google account..etc. When I build a release version, (with my signed keys), and install the apk file, when I run, the Googleapiclient fails to "connect", using the same google account that works under debug, giving me a "Sign in Failed" message, after it tries once to resolve.


回答1:


solution was here https://developers.google.com/drive/android/get-started

I need to create a seperate OAuth 2.0 client ID for the released version of my application, using the sha1 key from my release key.




回答2:


First, you need to start one intent to get the login credential

    if(mGoogleApiClient == null){
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Drive.API)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .enableAutoManage(this, this)
                .addScope(Drive.SCOPE_FILE)
                .addScope(Drive.SCOPE_APPFOLDER)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(AppIndex.API)
        .build();
    }
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, DRIVE_SIGNIN_RESULT);

No need to connect the mGoogleApiClient here you can create GoogleSignInResult object from the intent data you have received in onActivityResult

    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case DRIVE_SIGNIN_RESULT:
                GoogleSignInResult signInResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
                handleSignInResult(signInResult);
                break;
        }
    }

Connect mGoogleApiClient now

    private void handleSignInResult(GoogleSignInResult result) {
        if (result.isSuccess()) {
            GoogleSignInAccount account = result.getSignInAccount();
            mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
        }
    }


来源:https://stackoverflow.com/questions/29951403/google-android-drive-api-sign-in-fails-on-installed-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!