所以,我让用户在我的应用程序上登录他们的 Google+ 帐户。现在我可以获得他们的个人资料 URL 和显示名称。我现在想做的是收到他们的电子邮件。我不确定如何获取此信息。我已经添加了范围 https://www.googleapis.com/auth/plus.profile.emails.read
并且它在我登录时成功地请求我访问我的电子邮件的权限。我是现在只是不确定如何检索用户电子邮件。
对于用户名,我这样做:
String currentPersonName = mPlusClient.getCurrentPerson().getDisplayName();
所以基本上我想做的是这样的:
String currentPersonEmail = mPlusClient.getCurrentPerson().getEmail();
但显然这不是正确的方法。有谁知道如何获取电子邮件?谢谢。
最佳答案
获取用户的电子邮件地址:
private GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
emailAddr = Plus.AccountApi.getAccountName(mGoogleApiClient);
另一种方法是查询 Google+ 的 plus.profile.emails.read 范围(正如您所做的那样),但不使用 displayName,而是查找“emails”类型的 jsons,请参阅 code example here .
关于java - 在 Android 应用程序上从 Google Plus 帐户检索电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24962626/