繁体   English   中英

我必须为Drive.API和Auth.GOOGLE_SIGN_IN_API创建2个Google Api客户端吗?

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

我有一个Android应用程序,可以通过google登录/注销,这就是为什么我使用以下Google Api Client的原因:

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

但是当我想为驱动器连接设置此Google Api客户端时,如下所示:

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

我有 :

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

如果我要登出导致GoogleApiClient未连接(由于connectionFailed),然后发生错误

我的文件夹应用程序中有我的配置文件,请在Google Developer Console中查看所有信息,但我没有。

您只需要一个GoogleApiClient,重要的是通过使用requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))定义范围,即,

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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