2016-04-05 23 views
0

我試圖找到GoogleApiClient.Plus.API(機器人)用於獲取電子郵件gplus輪廓最新的解決方案來檢索gplus電子郵件。在互聯網,計算器,發現每一個例子是過時,過時,沒有用的。如何使用Android的

如果它只能從Auth.GOOGLE_SIGN_IN_API中獲取,然後是兩個步驟,從驗證API和休息從Plus.API賣到50信息的?

先感謝您的回答。

回答

0

首先,我假設你已經在

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.sign_in_button: 
      Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
      startActivityForResult(signInIntent, RC_SIGN_IN); 
      break; 
     } 
} 

的谷歌加號按鈕,在你onActivityResult你會趕上登錄結果

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    // Result returned from launching the Intent from and you can extract your user information there 
    if (requestCode == RC_SIGN_IN) { 
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     if (result.isSuccess()) { 
     // Signed in successfully, show authenticated UI. 
     GoogleSignInAccount acct = result.getSignInAccount(); 
     //This line is your need 
     String yourEmail = acct.getEmail(); 
     } 
    } 
} 
+0

不,我不想用這個GoogleSignInApi因爲我必須從gplus api中提取一些其他信息。所以你建議一個接一個地調用這兩個API。我覺得應該有一個方式來獲得個人或GPlus檔案的API的電子郵件。 – user2746732

0

這裏是如何獲取與相關聯的電子郵件該設備,並可能與您的應用程序:

Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ 
Account[] accounts = AccountManager.get(context).getAccounts(); 
for (Account account : accounts) { 
    if (emailPattern.matcher(account.name).matches()) { //If email matches the account associated with the device 
     String possibleEmail = account.name; 
     ... 
    } 
} 

讓我知道這是否工作

+0

我想下面使用m_GoogleApiClient =新GoogleApiClient.Builder(m_activity) .enableAutoManage(m_activity,這一點) .addConnectionCallbacks(本) .addOnConnectionFailedListener(本) .addApi(Plus.API) .addScope(加.SCOPE_PLUS_LOGIN) .build(); m_GoogleApiClient.connect(); – user2746732

0

後在最後這個帖子鬥爭兩天救了我的命.. How to get profile like gender from google signin in Android?

但API是過時的,沒有一點劃痕頭,並可能使其發揮作用。

創建谷歌的API客戶端這樣的

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

     m_GoogleApiClient = new GoogleApiClient.Builder(m_activity) 
       .enableAutoManage(m_activity, this) 
       .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
       .addApi(Plus.API) 
       .build(); 

然後在onActivityResult()

GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     Log.d(TAG, "handleSignInResult:" + result.isSuccess()); 
     if (result.isSuccess()) { 
      GoogleSignInAccount acct = result.getSignInAccount(); 
      fetchConnectedProfileInfo(); 
     } 

public void fetchConnectedProfileInfo() 
{ 
    Log.d(TAG, "fetchConnectedProfileInfo"); 
    if (m_GoogleApiClient.hasConnectedApi(Plus.API)) { 
     Plus.PeopleApi.load(m_GoogleApiClient, "me").setResultCallback(this); 
    } 
} 

請參閱我的github頁完整的代碼示例https://github.com/sandipsahoo2k2/social-login