2015-10-20 282 views
2

我已經開始通過參考鏈接https://developers.google.com/identity/sign-in/android/sign-in?configured在我的項目中集成google +登錄。現在我已經在開發者控制檯中啓用了Google+ API並配置了sha1證書,並下載了配置文件(google-services.json)並粘貼到我的項目的應用程序模塊中。如何從google + login android獲取個人資料信息?

執行應用程序後,我能夠成功登錄(連接)。 onConncected()函數也被調用。現在我用下面的代碼來檢索配置文件信息

@Override 
public void onConnected() { 

    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { 
    Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); 
    String personName = currentPerson.getDisplayName(); 
    String personPhoto = currentPerson.getImage().getUrl(); 
    String personGooglePlusProfile = currentPerson.getUrl(); 
    } 
} 

但getCurrentPerson()總是拋出null。我收到以下錯誤在我的logcat

BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/plus/v1/people/me 

我提到這些鏈接link1link2來解決問題。但結果總是拋出null。

我正在使用下面的代碼

 mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(Plus.API) 
      .addScope(new Scope(Scopes.PROFILE)) 
      .addScope(new Scope(Scopes.EMAIL)) 
      .build(); 

連接ApiClient我能夠通過Plus.AccountApi.getAccountName(mGoogleApiClient);順利拿到所連接的電子郵件,但無法獲取配置文件信息。

我錯過了我的代碼中的任何東西嗎? 有人能幫我解決這個問題嗎?

回答

0

如果已經啓用了谷歌+ API,然後與SHA1您的應用程序創建客戶端ID OG您editor.I希望它會運行並初始化googleApiClient如下

mGoogleApiClient = new GoogleApiClient.Builder(LoginActivity.this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this).addApi(Plus.API) 
      .addScope(Plus.SCOPE_PLUS_LOGIN).build(); 
+0

您好感謝您的回覆。如何創建客戶端ID?我們在哪裏使用這個? –

+0

它不用於應用程序,但它必須。谷歌develer控制檯 - >添加credentail-> 0身份驗證2.0客戶端ID,並提供您的sha1 –

+0

讓我知道如果面臨任何問題 –

相關問題