简体   繁体   中英

Do i have to create 2 Google Api Client for Drive.API and Auth.GOOGLE_SIGN_IN_API?

I have an android application where i sign in/out with google that's why i use the following Google Api Client :

        mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addOnConnectionFailedListener(this)
            .build();

But when i want to setup this Google Api client for drive connection like this :

        mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addApi(Drive.API)
            .addOnConnectionFailedListener(this)
            .build();

I have :

onConnectionFailed:ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null, message=null}

And then an error if i want to signout cause GoogleApiClient not connected (due to the connectionFailed)

I have my configuration file in my folder app, check all information in google developer console, i dont get it.

You just need one GoogleApiClient, the important thing is to define the scope by using requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) , ie,

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
                .requestEmail()
                .build();

 mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addApi(Drive.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM