我有一个Android应用程序,我使用谷歌登录/退出,这就是我使用以下Google Api客户端的原因:
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)
我在我的文件夹应用程序中有我的配置文件,检查谷歌开发者控制台中的所有信息,我不明白。
答案 0 :(得分:0)
您只需要一个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();