检索登录的Google Glass用户的电子邮件地址?

时间:2013-09-25 16:34:57

标签: google-mirror-api google-glass

我们正在尝试为Glass用户提供从时间轴卡请求发送电子邮件的功能。在通知回调Servlet上,我们尝试以下方法来检索用户的电子邮件地址:

    String userId = notification.getUserToken();
    Credential credential = AuthUtil.getCredential(userId);
    Mirror mirrorClient = MirrorClient.getMirror(credential);
    Contact contact = MirrorClient.getContact(credential, userId);

从经过身份验证的用户的UserInfo对象检索电子邮件时,我们不会收到结果。我们的应用程序具有以下适用于应用程序服务器的范围:

"https://www.googleapis.com/auth/glass.timeline "
"https://www.googleapis.com/auth/glass.location "
"https://www.googleapis.com/auth/userinfo.profile "
"https://www.googleapis.com/auth/userinfo.email "
"https://www.googleapis.com/auth/contacts"

我们是否可以检索经过身份验证的用户的电子邮件地址,是否存在我缺少的权限,还是有其他方式可以请求该数据?

2 个答案:

答案 0 :(得分:1)

您正在进行的getContact调用与用户的电子邮件地址无关。您可以在此处阅读联系人所指的内容:
https://developers.google.com/glass/contacts

要获取用户的电子邮件地址,我已成功使用相同的身份验证令牌来授权Glass镜像API应用,并添加了您提及的范围来调用此URL:
https://www.googleapis.com/userinfo/email?alt=json

此方法似乎在某些时候在初始授权后停止工作,因此请务必在用户首次授权应用并保存电子邮件时执行此操作。

虽然我之前也刚从AppEngine的UserService那里收到了电子邮件,但如果你碰巧在AppEngine上运行会更容易: https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/UserService

答案 1 :(得分:0)

所以问题归结为“为什么我没有收到我发送给Google镜像服务的此用户ID的联系信息?”

镜像服务仅提供您的Glassware添加的联系人的联系信息。有关Glass中的联系人以及如何添加联系人的详细信息,请参阅https://developers.google.com/glass/contacts。除非您已经使用此userId添加了Mirror Contact,否则您将无法获得任何回复。

镜像服务不提供对userinfo.info或userinfo.email中信息的直接访问。如果要将它们添加为Glass for Contact,则需要先使用OAuth2库将其取出。