Google Android Drive api sign in fails on installed version

时光总嘲笑我的痴心妄想 提交于 2019-12-05 23:05:24

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.

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