我开发了一个使用GoogleDrive api的android应用程序,
在调试或运行调试版本时,应用程序工作正常,并正确验证附加的谷歌帐户..等 . 当我构建发布版本(使用我的签名密钥),并安装apk文件时,当我运行时,Googleapiclient无法“连接”,使用在调试下工作的相同Google帐户,给我一个“登录失败”消息,尝试解决后 .
解决方案在这里https://developers.google.com/drive/android/get-started
我需要使用发行密钥中的sha1密钥为我的应用程序的已发布版本创建单独的OAuth 2.0客户端ID .
首先,您需要启动一个意图来获取登录凭据
if(mGoogleApiClient == null){ mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .enableAutoManage(this, this) .addScope(Drive.SCOPE_FILE) .addScope(Drive.SCOPE_APPFOLDER) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(AppIndex.API) .build(); } Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, DRIVE_SIGNIN_RESULT);
无需在此处连接mGoogleApiClient,您可以从onActivityResult中收到的意图数据创建GoogleSignInResult对象
if (resultCode == RESULT_OK) { switch (requestCode) { case DRIVE_SIGNIN_RESULT: GoogleSignInResult signInResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data); handleSignInResult(signInResult); break; } }
立即连接mGoogleApiClient
private void handleSignInResult(GoogleSignInResult result) { if (result.isSuccess()) { GoogleSignInAccount account = result.getSignInAccount(); mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL); } }
2 回答
解决方案在这里https://developers.google.com/drive/android/get-started
我需要使用发行密钥中的sha1密钥为我的应用程序的已发布版本创建单独的OAuth 2.0客户端ID .
首先,您需要启动一个意图来获取登录凭据
无需在此处连接mGoogleApiClient,您可以从onActivityResult中收到的意图数据创建GoogleSignInResult对象
立即连接mGoogleApiClient