Getting profiles

The Google+ Domains API provides Google Apps customers with API access to the Google+ profiles of users within their domain. You can also use the Admin SDK's Directory API to manage user's accounts, including retrieving profile and email information. Some types of information are only available from the Directory API, including email addresses.

Your app can retrieve this information by either having each user grant your app specific authorization through an OAuth 2.0 flow or by having the domain admin can grant your service account domain-wide delegation of authority.

Fetching the profile of a user provides you with a variety of fields from the user's profile, which can allow you to personalize apps within your organization, such as profile pictures on Team pages.

To retrieve a Google+ profile, your app must include the following scopes:

https://www.googleapis.com/auth/plus.me
Grants the app permission to use the special value me to represent the authenticated user. Does not apply to apps that use domain-wide delegation of authority.
https://www.googleapis.com/auth/plus.profiles.read
Required - Grants the app permission to read the user's public profile data as well as profile data that the authorized user is granted access to view.

The following examples demonstrate how to retrieve a user's Google+ profile. See Managing users with the Directory API if you require information from the user's G Suite account.

Java

// This sample assumes a client object `plusDomains` has been created
// and the request is for a currently authenticated user.
// To learn more about creating a client, see the OAuth 2.0 example:
//  https://developers.google.com/+/domains/authentication/

import com.google.api.services.plusDomains.model.Person;

Person mePerson = plusDomains.people().get("me").execute();

System.out.println("ID:\t" + mePerson.getId());
System.out.println("Display Name:\t" + mePerson.getDisplayName());
System.out.println("Image URL:\t" + mePerson.getImage().getUrl());
System.out.println("Profile URL:\t" + mePerson.getUrl());

Python

# This sample assumes a client object `service` has been created and the
# request is for a currently authenticated user.
# To learn more about creating a client, see the OAuth 2.0 example:
#  https://developers.google.com/+/domains/authentication/

people_service = service.people()
people_document = people_service.get(userId='me').execute()

print 'ID: %s' % people_document.get('id')
print 'Display name: %s' % people_document.get('displayName')
print 'Image URL: %s' % people_document.get('image').get('url')
print 'Profile URL: %s' % people_document.get('url')

Protocol

Request

GET https://www.googleapis.com/plusDomains/v1/people/{userId}

Replace {userId} with the ID of the specific user that you want to get information about. You can use the value me for requests that are made on behalf of an authenticated user. If your app uses domain-wide delegation of authority, you must specify the user ID.

Example

The following command demonstrates a request to the People.get method using the special value me and assumes that you already have an OAuth token for your user:

curl -v -H "Content-Type: application/json" -H "Authorization: OAuth$ACCESS_TOKEN" -X GET https://www.googleapis.com/plusDomains/v1/people/me

See the People.get REST API method.

See also

The Admin SDK provides a variety of APIs for working with your users' data within your domain. You can use the Directory API to manage your user's accounts, including retrieving profile information or updating a user's profile information. The Admin SDK does not update the user's Google+ profile, but might provide other capabilities that your app requires.

Enviar comentarios sobre…