0

公式サンプルアプリからコードをコピーしたにもかかわらず、アプリがPlayストアからリリースされると、認証同意画面が表示されません。 Google Apiデベロッパーコンソールで、公開用(私用のキーストアを使用)とデバッグ用(Androidスタジオのデバッグキーストアを使用)の2つのOAuth 2.0資格情報を正しく生成しました。Playサービス11.6:公開時にOAuth同意画面が表示されない

アップデート:デバッグモードの古い4.4エミュレータに私のアプリケーションをインストールしました新しいデバイスのリリースアプリケーションと同じ動作に気付きました。同意画面は表示されず、Logcatに次のメッセージが表示されます:

W/GooglePlayServicesUtil:Google Playサービスが古くなりました。 11717000が必要ですが、11509030

を発見し、それは、新しいGoogleApiインタフェースは/更新PlayServicesをインストールするようにユーザーに促すために失敗したということでした公式ドキュメントはそれを言っても?

build.gradle(アプリ)

compile 'com.google.android.gms:play-services-auth:11.6.0' 
compile 'com.google.android.gms:play-services-drive:11.6.0' 

のAndroidManifest.xml

<meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 
:ここ

は私のコードです

DriveActivity.java

private static final int REQUEST_CODE_SIGN_IN = 0; 

protected GoogleSignInClient mGoogleSignInClient; 
protected DriveClient mDriveClient; 
protected DriveResourceClient mDriveResourceClient; 

protected abstract void onDriveConnected(); 

    @Override 
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     switch (requestCode) { 
      case REQUEST_CODE_SIGN_IN: 
       if (resultCode == RESULT_OK) { 
        Task<GoogleSignInAccount> getAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data); 
        if (getAccountTask.isSuccessful()) { 
         initializeDriveClient(getAccountTask.getResult()); 
        } 
        else { 
         Toast.makeText(this, "Sign-in failed.", Toast.LENGTH_LONG).show(); 
        } 
       } 
       break; 
     } 
    } 

    protected void signIn() { 
     GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this); 
     if (signInAccount != null && signInAccount.getGrantedScopes().contains(Drive.SCOPE_FILE)) { 
      initializeDriveClient(signInAccount); 
     } 
     else { 
      GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
        .requestScopes(Drive.SCOPE_FILE) 
        .build(); 
      mGoogleSignInClient = GoogleSignIn.getClient(this, signInOptions); 
      startActivityForResult(mGoogleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN); 
     } 
    } 

    private void initializeDriveClient(GoogleSignInAccount signInAccount) { 
     mDriveClient = Drive.getDriveClient(this, signInAccount); 
     mDriveResourceClient = Drive.getDriveResourceClient(this, signInAccount); 
     onDriveConnected(); 
    } 

答えて

0

私は自分の質問に答えます。問題は、Google Playサービスが更新されていないことです。最近のGoogleApiインターフェースではそれが確認されません(バグかもしれません)。 だから、認証をしようとする前にチェックを入れてあります。

protected void signIn() { 
    if (checkPlayServices()) { 
     ... 
    } 
} 

private boolean checkPlayServices() { 
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance(); 
    int result = googleAPI.isGooglePlayServicesAvailable(this); 
    if (result != ConnectionResult.SUCCESS) { 
     if (googleAPI.isUserResolvableError(result)) { 
      googleAPI.getErrorDialog(this, result, PLAY_SERVICES_RESOLUTION_REQUEST).show(); 
     } 
     else { 
      Toast.makeText(this, R.string.message_unsupported_device, Toast.LENGTH_LONG).show(); 
     } 
     return false; 
    } 
    return true; 
} 

は、それが他の誰かに役立ちます願っています!

+0

GoogleSignIn.getClient()にアクティビティを渡すと、Google Playサービスの更新を促すダイアログが表示されます。物理的なデバイスで試してみませんか? Playストアのないエミュレータの場合、動作は若干異なります(つまり、ログに表示されるエラーのみ)。 –

+0

残念なことに物理デバイスでもダイアログが表示されません... – Alessandro

+0

うーん...これは期待していません。 Google PlayサービスがSDKより古い場合、getClient(Activity、options)はダイアログを表示します。 DriveActivity.javaに貼り付けたものはアクティビティコードからの直接コピーですか?あなたの物理的なデバイスは11.6よりも古いPlayサービスを持っていますか? –

0

GoogleSignIn.getClient(this/* activity */signInOptions)は、必要に応じてPlayサービスの更新を自動的に促す必要があります。

最新の11.6 SDKでは、この機能がtargetSdkVersion 26で一時的に壊れています。今後のリリースで修正されるまで、これらの条件でGoogleApiAvailability.showErrorDialogFragment()を使用することを検討してください。

関連する問題