11

I am trying to get email and id of user through chrome identity api.

I am doing this

  chrome.identity.getProfileUserInfo(function(userinfo){
    console.log("userinfo",userinfo);
    email=userinfo.email;
    uniqueId=userinfo.id;
  });

I have specified identity permission and have added https://www.googleapis.com/auth/userinfo.email in scopes.

User is logged in through chrome.identity.getAuthToken and I have access token.

console.log("userinfo",userinfo); returns userinfo Object {email: "", id: ""}

Harshil Pansare
  • 1,117
  • 1
  • 13
  • 37

2 Answers2

21

The getProfileUserInfo documentation says:

  • email: Empty if the user is not signed in or the identity.email manifest permission is not specified.
  • id: Empty if the user is not signed in or (in M41+) the identity.email manifest permission is not specified.

Edit manifest.json to include both permissions:

"permissions": ["identity", "identity.email"]
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
8

In addition to having the identity.email permission, as posted in the related Chrome issue for this subject, users must have their profile syncing turned on under chrome://settings -> People -> Sync for their ID and email to show up using chrome.identity.getProfileUserInfo.

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
  • I've the same problem with me. By the time, the user accepts the sync-in, the event has been fired (or listened) and the email_id returned is empty. Any resolution to this? – Praful Bagai May 27 '19 at 19:50
  • I would guess not besides them refreshing the page or whatever that is calling it. – Zach Saucier May 27 '19 at 23:13
  • 4
    You can add `{accountStatus: 'ANY'}` as the first parameter to `getProfileUserInfo`, the default is 'SYNC'. – mal Oct 01 '21 at 06:04
  • @mal's suggestion was the key for me. – Zach Jan 24 '23 at 04:33