简体   繁体   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?

I have an android application where i sign in/out with google that's why i use the following Google Api Client : 我有一个Android应用程序,可以通过google登录/注销,这就是为什么我使用以下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 : 但是当我想为驱动器连接设置此Google Api客户端时,如下所示:

        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) 如果我要登出导致GoogleApiClient未连接(由于connectionFailed),然后发生错误

I have my configuration file in my folder app, check all information in google developer console, i dont get it. 我的文件夹应用程序中有我的配置文件,请在Google Developer Console中查看所有信息,但我没有。

You just need one GoogleApiClient, the important thing is to define the scope by using requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) , ie, 您只需要一个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.

相关问题 Auth.GOOGLE_SIGN_IN_API不能与Games.API一起使用 - Auth.GOOGLE_SIGN_IN_API cannot be used with Games.API 无法解析符号GOOGLE_SIGN_IN_API。.我的应用程序中的Google登录,无法访问变量Auth.GOOGLE_SIGN_IN_API - Cannot resolve symbol GOOGLE_SIGN_IN_API.. Google sign-in in my app, Unable to access variable Auth.GOOGLE_SIGN_IN_API 当使用`FusedLocationApi`时,android在`LocationServices.API`和`Auth.GOOGLE_SIGN_IN_API`之间发生冲突 - android clashed between `LocationServices.API` and `Auth.GOOGLE_SIGN_IN_API` when using `FusedLocationApi` 如何使用Drive.API从Google云端硬盘下载文件? - How to download file from Google Drive using Drive.API? Google云端硬盘API-未登录 - Google Drive API - Not Sign In java.lang.IllegalStateException:使用Auth.GOOGLE_SIGN_IN_API时不得在GoogleApiClient.Builder中设置范围 - java.lang.IllegalStateException: Must not set scopes in GoogleApiClient.Builder when using Auth.GOOGLE_SIGN_IN_API Google Drive Android Drive.API Android可以与其他API结合使用吗? - Can Google Drive Android Drive.API Android be combined with other API's? 无法添加Google Drive Drive.API,Google授权工作正常 - Cannot add Google Drive Drive.API, Google authorization worked fine 登入Google API用户端时发生IllegalStateException - IllegalStateException on sign to Google api client Google Drive REST API注销 - Google drive REST API sign out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM