0

I'm trying to use Google's 'google-api-nodejs-client' package (https://github.com/google/google-api-nodejs-client) to handle OAuth 2.0 authentication.

I've modified the example in examples/oauth2.js to console.log the entire profile object.

What scope can I use to correctly extract users' 'givenName' and 'familyName' if they're authenticating using a Google Apps account? Using the following scope:

scope: [
  'https://www.googleapis.com/auth/plus.login',
  'https://www.googleapis.com/auth/plus.profile.emails.read'
]

returns the following response once authenticated:

{ kind: 'plus#person',
  etag: '"LONG STRING"',
  emails: [ { value: 'example@example.example', type: 'account' } ],
  objectType: 'person',
  id: '123456',
  displayName: '',
  name: { familyName: '', givenName: '' },
  image:
   { url: 'https://lh3.googleusercontent.com/ etc etc',
     isDefault: false },
  isPlusUser: false,
  language: 'en_GB',
  circledByCount: 0,
  verified: false,
  domain: 'example.example' }
neurotech
  • 5
  • 3

1 Answers1

0

I tried fooling around with the API on the API Explorer (https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get?userId=me) and only needed the 'https://www.googleapis.com/auth/plus.login' scope to get my familyName and givenName.

Perhaps the user that you are requesting the data from does not have a given and family name set?

Ryan Seys
  • 264
  • 1
  • 9
  • It's definitely set _somewhere_ as I'm using my own account to test. When I navigate to my consent page it renders my first and last name on the 'Choose an account' widget (not sure if that matters). – neurotech Jul 25 '14 at 05:07
  • Okay. I tried the API Explorer and it returned the correct name information: "displayName": "Tim Douglas", "name": { "familyName": "Douglas", "givenName": "Tim" } – neurotech Jul 25 '14 at 05:22
  • I found where those values are coming from. The API explorer allows you to use the soon-to-be-deprecated 'https://www.googleapis.com/auth/userinfo.profile' scope, which is the scope that is returning the aforementioned name object. – neurotech Jul 25 '14 at 05:35
  • Good to know! Perhaps I had already auth'd the API Explorer with that scope so it just automatically pulled that information. Glad you figured it out :) – Ryan Seys Jul 25 '14 at 16:26