How can we get the phone number with Google OAuth API and facebook API used for social login?
Solution 1
if you want to get user phone numbers you have to have authorization from the user: see the following info page : https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
ask the user for this scope of authorization : https://www.googleapis.com/auth/admin.directory.user.readonly
after you have authorization from user run the folowing request : GET https://www.googleapis.com/admin/directory/v1/users/userKey
the response will be a JSON response formatted as followed: https://developers.google.com/admin-sdk/directory/v1/reference/users#resource
one of the attributes is phone list.
hope it helps.
Solution 2
You can use google's people API to get the user's phone numbers. To explore more you can try yourself. Steps to explore:
- Visit this link.
- Select https://www.googleapis.com/auth/user.phonenumbers.read permission in People API v1 section
- Click on Authorize API
- Choose the account to log in
- Grant permission
- Click Exchange authorization code for tokens
- Enter https://people.googleapis.com/v1/people/138262720636785143353?personFields=phoneNumbers,emailAddresses link, make sure you replace the UID
- Click on send request to see the response
Nidhi_s1
Updated on July 23, 2020Comments
-
Nidhi_s1 over 3 years
How can we get the phone number with Google OAuth API login.
I am using scopes as
'scope' : 'https://mail.google.com https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.login '
and the request is as
var request = gapi.client.plus.people.get({'userId': 'me'});
Is there any scope we can use to get it.
I am getting response as with no sight of phone number :
{ "kind": "plus#person", "etag": "\"vPymIyv1bT9LfmoUujkgN2yLMK0\"", "gender": "male", "emails": [ { "value": "[email protected]", "type": "account" } ], "urls": [ { "value": "http://picasaweb.google.com/XXX", "type": "otherProfile", "label": "Picasa Web Albums" } ], "objectType": "person", "id": "4354354334435465", "displayName": "XXXXX YYYY", "name": { "familyName": "XXX", "givenName": "YYYYY" }, "url": "https://plus.google.com/1100335464643327", "image": { "url": "https://lh3.googleusercontent.com/-fgsdgfgU9-jU/AAAAAAAAAAI/AAAAAAAADkM/fgffdgdkM/photo.jpg?sz=50", "isDefault": false }, "isPlusUser": true, "language": "en", "ageRange": { "min": 21 }, "circledByCount": 59, "verified": false }
-
Noam about 3 yearsWhen I also asked for the googleapis.com/auth/userinfo.profile permission, I could replace the UID in step 7 with "me" and get a reply, but it didn't include the phone number.
-
SebastianG over 2 yearsHmm, I've used this after adding and verifying a phone number for my profile and I'm not getting the phone number data from the Oauth playground api :(
-
Mathews Mathai about 2 years@SebastianG The scope description says
Get the phone numbers in user's Google profile
. This most likely means the phone numbers linked to or present on Google plus profile and not the Google Account itself. If you look at responses for other scopes likebirthdays
returns an array ofbirthdays
with source type asAccount
andProfile
respectively. I believe phone numbers don't work that way. Check this Out -
Mathews Mathai about 2 years@SebastianG I just noticed phone numbers are made available if the user adds them in the
Contact Info
section under google personal info (About me) settings. myaccount.google.com/profile