0
votes

If I open someone's Google Plus Profile Page I see contact info and information shared on Google Plus. I looking for similar information on Google API. I'm trying to fetch list of user's contacts with email and google plus profile id, that's all.

Here I can fetch user connections with Google Plus profile url but without email or phone number.

https://people.googleapis.com/v1/people/me/connections

Here I can fetch person contacts with email and phone number (OAuth2) - without Google Plus profile url nor id

https://www.google.com/m8/feeds/contacts/{GOOGLE_ACCOUNT_NAME}%40gmail.com/full?alt=json

But I don't know how to combine this two outputs, to get have Google Plus profile url and contact information.

2

2 Answers

1
votes

You are correct. To retrieve profile information for a user, use the people.get API method. To get profile information for the currently authorized user, use the userId value of me.

gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
console.log('Retrieved profile for:' + resp.displayName);
});
});

Note that this method requires authentication using a token that has been granted the OAuth scope https://www.googleapis.com/auth/plus.login or https://www.googleapis.com/auth/plus.me.

Plus.People.List listPeople = plus.people().list(
"me", "visible");
listPeople.setMaxResults(5L);

PeopleFeed peopleFeed = listPeople.execute();
List<Person> people = peopleFeed.getItems();

// Loop through until we arrive at an empty page
while (people != null) {
for (Person person : people) {
System.out.println(person.getDisplayName());
}

// We will know we are on the last page when the next page token is
// null.
// If this is the case, break.
if (peopleFeed.getNextPageToken() == null) {
break;
}

// Prepare the next page of results
listPeople.setPageToken(peopleFeed.getNextPageToken());

// Execute and process the next page request
peopleFeed = listPeople.execute();
people = peopleFeed.getItems();
}

Here's a related SO ticket which discuss how to fetch user email from Google+ Oauth: How to get user email from google plus oauth

0
votes

You can use the Google Api to fetch the user profile. For this

  1. Create project in google api console.Configure the credentials client id,client secret. Add your redirect uri.

  2. Authorize the user with OAuth2.0 from your project with scopes https://www.googleapis.com/auth/plus.me , https://www.googleapis.com/auth/plus.login.

  3. Retrieve the response code after authorization.Give POST method to the token endpoint url.

  4. Retrieve the access_token, refresh_token,id_token etc from gooogle plus.

  5. By using the access_token. call GET method to the url "https://www.googleapis.com/plus/v1/people/me/?access_token='{YOUR_ACCESS_TOKEN}'".

You will be given by an json array containing the authorized user profile details like email, name, id etc.