Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we get the phone number with Google OAuth API and facebook API used for social login?

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
}
like image 764
Nidhi_s1 Avatar asked Jun 17 '16 07:06

Nidhi_s1


People also ask

How does OAuth work with Facebook?

In case you're wondering what OAuth2 is, it's the protocol that enables anyone to log in with their Facebook account. It powers the “Log in with Facebook” button in apps and on websites everywhere.


2 Answers

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.

like image 105
ddor254 Avatar answered Nov 02 '22 05:11

ddor254


You can use google's people API to get the user's phone numbers. To explore more you can try yourself. Steps to explore:

  1. Visit this link.
  2. Select https://www.googleapis.com/auth/user.phonenumbers.read permission in People API v1 section
  3. Click on Authorize API
  4. Choose the account to log in
  5. Grant permission
  6. Click Exchange authorization code for tokens
  7. Enter https://people.googleapis.com/v1/people/138262720636785143353?personFields=phoneNumbers,emailAddresses link, make sure you replace the UID
  8. Click on send request to see the response
like image 39
Imran Ahmad Avatar answered Nov 02 '22 06:11

Imran Ahmad