因此,我要让用户在我的应用上登录他们的Google+帐户。现在我可以获取他们的个人资料网址和显示名称。我现在要做的就是收到他们的电子邮件。我不确定如何获取这些信息。我没有添加范围https://www.googleapis.com/auth/plus.profile.emails.read
,它在我登录时成功请求我允许访问我的电子邮件。我现在只是不确定如何检索用户电子邮件。
对于用户名,我这样做:
String currentPersonName = mPlusClient.getCurrentPerson().getDisplayName();
基本上我想做的就是这样:
String currentPersonEmail = mPlusClient.getCurrentPerson().getEmail();
但显然这不是正确的方法。有谁知道如何收到电子邮件?感谢。
答案 0 :(得分:6)
获取用户的电子邮件地址:
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,而是查找“电子邮件”类型jsons,请参阅code example here。