2

We are attempting to be able to provide the ability for a Glass user to request an email to be sent to them from a Timeline Card. On the notify callback Servlet, we are attempting the following to retrieve a user's email address:

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

We do not get a result back when retrieving an email off of the UserInfo object of a authenticated user. Our application has the following scopes available to the application server:

"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"

Are we allowed to retrieve the authenticated user's email address, is there a permission I am missing or is there another means by which to request that data?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Dayel Ostraco
  • 1,753
  • 1
  • 13
  • 15
  • Can you clarify what language you are using and exactly which library you are using? – Prisoner Sep 25 '13 at 17:25
  • Can you also confirm where you're getting the Credential object from, and that this is the credential object for an authenticated user? – Prisoner Sep 25 '13 at 17:35
  • We used the Java starter project leveraging the google-api-services-mirror Maven dependency. We are using the Google Credential from their OAuth2 client Java library. We haven't had any issues with authentication thus far and have been able to create entire timelines and get user locations. – Dayel Ostraco Sep 25 '13 at 20:29
  • What is confusing to me is that I can't find any version of MirrorClient that has the getUserInfo() method. If it is calling the usual OAuth2 endpoints for userinfo, I would expect it to work, but I'm not sure what is really going on behind the scenes here. – Prisoner Sep 27 '13 at 13:57
  • You are correct. I forgot to remove the custom UserInfo object and method. I have updated the question to include Google only libraries and we continue to get null on the MirrorClient.getContact(credential, userId) line. – Dayel Ostraco Sep 27 '13 at 16:40

2 Answers2

1

The getContact call you are making doesn't have anything to do with the user's email address. You can read up on what Contact is referring to here:
https://developers.google.com/glass/contacts

To get the user's email address, I've successfully used the same auth token used to authorize the Glass mirror API app with the added scope you mention to call this URL:
https://www.googleapis.com/userinfo/email?alt=json

This method seems to stop working after the initial authorization at some point, so be sure to do it when the user first authorizes the app and save off the email.

Although I've also just gotten the email off AppEngine's UserService before as well, which is easier if you happen to be running on AppEngine:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/UserService

Lance Nanek
  • 6,377
  • 2
  • 24
  • 19
  • Whew! That totally worked. We are now leveraging the Mirror API to return an authenticated Credential, then we use the accessToken from that object to make a GET call on the URL you provided and it works perfectly. Thank you so much for your help with this @lance-nanek! – Dayel Ostraco Oct 21 '13 at 18:35
0

So the question boils down to "Why am I not getting contact info for this userID that I am sending to the Google Mirror service?"

The Mirror service only provides contact information for Contacts that your Glassware has added. See https://developers.google.com/glass/contacts for more about Contacts in Glass and how to add Contacts. Unless you have already added a Mirror Contact with this userId, you won't get anything back.

The Mirror service does not provide direct access to the information from userinfo.info or userinfo.email. You will need to get it out using the OAuth2 libraries first if you want to add them as a Contact for Glass.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • 1
    Thank you @Prisoner! With your insight into the Contacts API and @LanceNanek help pointing us to the correct service, we were able to solve this. Much appreciated! – Dayel Ostraco Oct 21 '13 at 18:38
  • Glad we were able to help @DayelOstraco. I'm sure both of us would appreciate the up-vote as well. {: Have fun with your Glassware! – Prisoner Oct 21 '13 at 19:28