public class

PlusClient

extends Object
implements GooglePlayServicesClient
java.lang.Object
   ↳ com.google.android.gms.plus.PlusClient

Class Overview

The main entry point for Google+ integration. Use the PlusClient after the asynchronous connect() method has been called and your listener's onConnected(android.os.Bundle) method is called.

When your app is done using PlusClient, call disconnect(), even if the async result from connect() has not yet been delivered.

You should instantiate this object in your Activity's onCreate(Bundle) method and then call connect() in onStart() and disconnect() in onStop(), regardless of the state.

Summary

Nested Classes
class PlusClient.Builder Builder to configure a PlusClient for communicating with the Google+ APIs. 
interface PlusClient.OnAccessRevokedListener Listener interface for when the token revocation request has completed. 
interface PlusClient.OnMomentsLoadedListener Listener interface for when moments are loaded. 
interface PlusClient.OnPeopleLoadedListener Listener interface for when a collection of people are loaded. 
interface PlusClient.OrderBy Constants to declare the order to return people in. 
Public Methods
void clearDefaultAccount()
Remove the default account set in Google Play services for your app.
void connect()
Connects the client to Google Play services.
void disconnect()
Closes the connection to Google Play services.
String getAccountName()
Gets the account name resolved by Google Play services.
Person getCurrentPerson()
Returns profile information for the current user.
boolean isConnected()
Checks if the client is currently connected to the service, so that requests to other methods will succeed.
boolean isConnecting()
Checks if the client is attempting to connect to the service.
boolean isConnectionCallbacksRegistered(GooglePlayServicesClient.ConnectionCallbacks listener)
Returns true if the specified listener is currently registered to receive connection events.
boolean isConnectionFailedListenerRegistered(GooglePlayServicesClient.OnConnectionFailedListener listener)
Returns true if the specified listener is currently registered to receive connection failed events.
void loadMoments(PlusClient.OnMomentsLoadedListener listener, int maxResults, String pageToken, Uri targetUrl, String type, String userId)
List all of the moments for a particular user.
void loadMoments(PlusClient.OnMomentsLoadedListener listener)
List all of the moments for the currently signed-in user.
void loadPeople(PlusClient.OnPeopleLoadedListener listener, Collection<String> personIds)
Loads a list of specified people.
void loadPeople(PlusClient.OnPeopleLoadedListener listener, String... personIds)
void loadVisiblePeople(PlusClient.OnPeopleLoadedListener listener, String pageToken)
Loads the list of visible people in the user's circles.
void loadVisiblePeople(PlusClient.OnPeopleLoadedListener listener, int orderBy, String pageToken)
Loads the list of visible people in the user's circles.
void registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener)
Registers a listener to receive connection events from this GooglePlayServicesClient.
void registerConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener)
Registers a listener to receive connection failed events from this GooglePlayServicesClient.
void removeMoment(String momentId)
Delete a moment.
void revokeAccessAndDisconnect(PlusClient.OnAccessRevokedListener listener)
Revokes access given to the current application.
void unregisterConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener)
Removes a connection listener from this GooglePlayServicesClient.
void unregisterConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener)
Removes a connection failed listener from the GooglePlayServicesClient.
void writeMoment(Moment moment)
Writes a moment.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.android.gms.common.GooglePlayServicesClient

Public Methods

public void clearDefaultAccount ()

Remove the default account set in Google Play services for your app. Subsequent calls to connect() will return a resolution intent that will let the user select a different account.

If the user chooses the same account, no consent will be required since access to the app is not revoked. Users should also be given the option to revoke access with revokeAccessAndDisconnect(PlusClient.OnAccessRevokedListener).

public void connect ()

Connects the client to Google Play services. This method returns immediately, and connects to the service in the background. If the connection is successful, onConnected(Bundle) is called. On a failure, onConnectionFailed(ConnectionResult) is called.

public void disconnect ()

Closes the connection to Google Play services. No calls can be made on this object after calling this method.

public String getAccountName ()

Gets the account name resolved by Google Play services. The permission <uses-permission android:name="android.permission.GET_ACCOUNTS" /> must be declared in your AndroidManifest.xml to use this method.

Returns
  • The account name. If the user has not selected an account, null is returned.
Throws
SecurityException If your app doesn't have the GET_ACCOUNTS permission.

public Person getCurrentPerson ()

Returns profile information for the current user. For more information, see: https://developers.google.com/+/api/latest/people/get.

This method requires the OAuth 2.0 scope PLUS_PROFILE or PLUS_LOGIN specified in the PlusClient.Builder.

This method can return null if the required scopes weren't specified in the PlusClient.Builder, or if there was a network error while connecting.

Returns
  • Profile information for the current user, if available, or null otherwise.

public boolean isConnected ()

Checks if the client is currently connected to the service, so that requests to other methods will succeed. Applications should guard client actions caused by the user with a call to this method.

Returns
  • true if the client is connected to the service.

public boolean isConnecting ()

Checks if the client is attempting to connect to the service.

Returns
  • true if the client is attempting to connect to the service.

public boolean isConnectionCallbacksRegistered (GooglePlayServicesClient.ConnectionCallbacks listener)

Returns true if the specified listener is currently registered to receive connection events.

Parameters
listener The listener to check for.
Returns
  • true if the specified listener is currently registered to receive connection events.

public boolean isConnectionFailedListenerRegistered (GooglePlayServicesClient.OnConnectionFailedListener listener)

Returns true if the specified listener is currently registered to receive connection failed events.

Parameters
listener The listener to check for.
Returns
  • true if the specified listener is currently registered to receive connection failed events.

public void loadMoments (PlusClient.OnMomentsLoadedListener listener, int maxResults, String pageToken, Uri targetUrl, String type, String userId)

List all of the moments for a particular user. For more information, see https://developers.google.com/+/api/latest/moments/list.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder.

Parameters
listener The PlusClient.OnMomentsLoadedListener to receive a callback when the moments are loaded.
maxResults The maximum number of moments to include in the response, which is used for paging. For any response, the actual number returned might be less than the specified maxResults.
pageToken The continuation token, which is used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response.
targetUrl Only moments containing this targetUrl will be returned.
type Only moments of this type will be returned.
userId The ID of the user to get moments for. The special value "me" can be used to indicate the authenticated user.

public void loadMoments (PlusClient.OnMomentsLoadedListener listener)

List all of the moments for the currently signed-in user. For more information, see https://developers.google.com/+/api/latest/moments/list.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder.

Parameters
listener The PlusClient.OnMomentsLoadedListener to receive a callback when the moments are loaded.

public void loadPeople (PlusClient.OnPeopleLoadedListener listener, Collection<String> personIds)

Loads a list of specified people.

This call returns all information in Person, but only for the people specified and for data that is public in their profiles.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder

Parameters
listener The PlusClient.OnPeopleLoadedListener to receive a callback when the people are loaded.
personIds The ids of people to load. This should match the user id that would be sent to https://developers.google.com/+/api/latest/people/get

public void loadPeople (PlusClient.OnPeopleLoadedListener listener, String... personIds)

public void loadVisiblePeople (PlusClient.OnPeopleLoadedListener listener, String pageToken)

Loads the list of visible people in the user's circles. For more information, see: https://developers.google.com/+/api/latest/people/list.

Each Person will contain the id, displayName, image, objectType, and url fields populated. To retrieve additional profile data, use the loadPeople(PlusClient.OnPeopleLoadedListener, String...) method.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder

Parameters
listener The PlusClient.OnPeopleLoadedListener to receive a callback when the people are loaded.

public void loadVisiblePeople (PlusClient.OnPeopleLoadedListener listener, int orderBy, String pageToken)

Loads the list of visible people in the user's circles. For more information, see: https://developers.google.com/+/api/latest/people/list.

Each Person will contain the id, displayName, image, objectType, and url fields populated. To retrieve additional profile data, use the loadPeople(PlusClient.OnPeopleLoadedListener, String...) method.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder

Parameters
listener The PlusClient.OnPeopleLoadedListener to receive a callback when the people are loaded.
orderBy The order to return people in. Valid values are:

ALPHABETICAL - Order the people by their display name. BEST - Order people based on the relevance to the viewer.

public void registerConnectionCallbacks (GooglePlayServicesClient.ConnectionCallbacks listener)

Registers a listener to receive connection events from this GooglePlayServicesClient. If the service is already connected, the listener's onConnected(Bundle) method will be called immediately. Applications should balance calls to this method with calls to unregisterConnectionCallbacks(ConnectionCallbacks) to avoid leaking resources.

If the specified listener is already registered to receive connection events, this method will not add a duplicate entry for the same listener, but will still call the listener's onConnected(Bundle) method if currently connected.

Note that the order of messages received here may not be stable, so clients should not rely on the order that multiple listeners receive events in.

Parameters
listener the listener where the results of the asynchronous connect() call are delivered.

public void registerConnectionFailedListener (GooglePlayServicesClient.OnConnectionFailedListener listener)

Registers a listener to receive connection failed events from this GooglePlayServicesClient. Unlike registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks), if the service is not already connected, the listener's onConnectionFailed(ConnectionResult) method will not be called immediately. Applications should balance calls to this method with calls to unregisterConnectionFailedListener(OnConnectionFailedListener) to avoid leaking resources.

If the specified listener is already registered to receive connection failed events, this method will not add a duplicate entry for the same listener.

Note that the order of messages received here may not be stable, so clients should not rely on the order that multiple listeners receive events in.

Parameters
listener the listener where the results of the asynchronous connect() call are delivered.

public void removeMoment (String momentId)

Delete a moment. For more information, see https://developers.google.com/+/api/latest/moments/remove.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder.

Parameters
momentId The ID of the moment to delete.

public void revokeAccessAndDisconnect (PlusClient.OnAccessRevokedListener listener)

Revokes access given to the current application.

Parameters
listener The PlusClient.OnAccessRevokedListener to receive a callback when the token is revoked.

public void unregisterConnectionCallbacks (GooglePlayServicesClient.ConnectionCallbacks listener)

Removes a connection listener from this GooglePlayServicesClient. Note that removing a listener does not generate any callbacks.

If the specified listener is not currently registered to receive connection events, this method will have no effect.

Parameters
listener the listener to unregister.

public void unregisterConnectionFailedListener (GooglePlayServicesClient.OnConnectionFailedListener listener)

Removes a connection failed listener from the GooglePlayServicesClient. Note that removing a listener does not generate any callbacks.

If the specified listener is not currently registered to receive connection failed events, this method will have no effect.

Parameters
listener the listener to unregister.

public void writeMoment (Moment moment)

Writes a moment. For more information, see https://developers.google.com/+/api/latest/moments/insert.

This is a fire-and-forget method that writes the user's moment asynchronously. If there is a network error, Google Play services attempts to send the request again when the device comes back online. Requests can fail if there are problems with the account or format of specified in moment. To debug, run adb logcat in a terminal and find errors related to moments in the output.

This method requires the PLUS_LOGIN OAuth 2.0 scope specified in the PlusClient.Builder.

Parameters
moment The moment description.