2016-08-10 6 views
1

私のアプリにgoogle plus loginを統合しようとしています。しかし、getServerAuthCode()とgetIdToken()を呼び出すと、常にnullが返されます。私は正確な問題が何であるか把握できません。Google plus login getIdTokenがnullを返す

 private void handleSignInResult (GoogleSignInResult result) 
    { 
     Log.d(TAG, "handleSignInResult:" + result.isSuccess()); 
     if (result.isSuccess()) { 

      GoogleSignInAccount acct = result.getSignInAccount(); 
      Toast.makeText(getApplicationContext(), acct.getDisplayName() + "-" + acct.getEmail() + "-" + acct.getServerAuthCode(), Toast.LENGTH_SHORT).show(); 
      Log.d(TAG, "Server Token google" + acct.getServerAuthCode() + "-ID token" + acct.getIdToken()); 
      create_account_method(acct.getEmail(), acct.getDisplayName(), acct.getServerAuthCode()); 

     } else { 

     } 
    } 
+0

あなたPlus.APIを使用して、Auth.GOOGLE_SIGN_IN_APIを使用することをお勧めして@Jemo Mgebrishviliソリューションをたどると思います。 – Kathi

答えて

1

正しく初期化していますか?

public void gmailLogin(GoogleApiClient mGoogleApiClient) { 
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
    startActivityForResult(signInIntent, RC_SIGN_IN); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == RC_SIGN_IN) { 
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
    } 
} 
+1

はい私はすでに初期化していますが、getServerAuthCode()とgetIdToken()を呼び出すとまだnullになっています –

+0

あなたはそれを解決しましたか? – user2507

3

おそらくあなたはすでに解決したが、今後の参考のため、ログインボタンをクリックした後、この

onResume() { 
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
      .requestEmail() 
      .requestProfile() 
      .requestScopes(new Scope(Scopes.PLUS_ME)) 
      .requestScopes(new Scope(Scopes.PLUS_LOGIN)) 
      .build(); 

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

を試してみてください。私は同じ問題を抱えていて、その解決策は実際は非常に簡単でした。

このlinkでgetIdTokenのマニュアルを読んだ後、私はそれは私がGoogleSignInOptionsオブジェクトを構築したときrequestIdToken(serverClientId)と.requestServerAuthCode(偽serverClientIdは、)を呼び出す欠落していたことを考え出しました。ここで

はコードです:

String serverClientId = getResources().getString(R.string.google_server_client_id); 

GoogleSignInOptions gso = new GoogleSignInOptions 
       .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestEmail() 
       .requestIdToken(serverClientId) 
       .requestServerAuthCode(serverClientId, false) 
       .build(); 
関連する問題