2016-07-27 74 views
0

我有一个Android应用程序,我退出/与谷歌,这就是为什么我用下面的谷歌API客户端:我是否必须为Drive.API和Auth.GOOGLE_SIGN_IN_API创建2个Google Api客户端?

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

但是,当我不想设置此谷歌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} 

然后一个错误,如果我想signout引起GoogleApiClient没有连接(由于connectionFa iled)

我有我的配置文件在我的文件夹应用程序,检查所有信息在谷歌开发者控制台,我没有得到它。

回答

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(); 
相关问题