java.lang.Object | |
↳ | com.google.android.gms.plus.PlusClient |
The main entry point for Google+ integration.
Use the PlusClient after the asynchronous connect()
method
has been called and your listener's
onConnected()
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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
PlusClient.Builder | Builder to create a PlusClient to connect to Google Play services. |
||||||||||
PlusClient.OnAccessRevokedListener | Listener interface for when the token revocation request has completed. | ||||||||||
PlusClient.OnMomentsLoadedListener | Listener interface for when moments are loaded. | ||||||||||
PlusClient.OnPeopleLoadedListener | Listener interface for when a collection of people are loaded. | ||||||||||
PlusClient.OnPersonLoadedListener | Listener interface for when a Person is
loaded |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEFAULT_ACCOUNT | Specify < as the account name to indicate that the default account
on the device should be used. |
|||||||||
String | KEY_REQUEST_VISIBLE_ACTIVITIES | Bundle key for specifying which user's app activity (moment) types can be written to Google. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clears the default account for this
PlusClient instance. | |||||||||||
Connects the client to Google Play services.
| |||||||||||
Closes the connection to Google Play services.
| |||||||||||
Gets the account name resolved by Google Play services.
| |||||||||||
Returns profile information for the current user.
| |||||||||||
Checks if the client is currently connected to the service, so that
requests to other methods will succeed.
| |||||||||||
Returns true if the specified listener is currently registered to
receive connection events.
| |||||||||||
Returns true if the specified listener is currently registered to
receive connection failed events.
| |||||||||||
List all of the moments for a particular user.
| |||||||||||
List all of the moments for the currently signed-in user.
| |||||||||||
Loads a list of people in the specified collection.
| |||||||||||
Loads a list of people in the specified collection.
| |||||||||||
Loads profile information for a specified Google+ user.
| |||||||||||
Registers a listener to receive connection events from this
GooglePlayServicesClient . | |||||||||||
Registers a listener to receive connection failed events from this
GooglePlayServicesClient . | |||||||||||
Delete a moment.
| |||||||||||
Revokes access given to the current application.
| |||||||||||
Removes a connection listener from this
GooglePlayServicesClient . | |||||||||||
Removes a connection failed listener from the
GooglePlayServicesClient . | |||||||||||
Writes a moment.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
com.google.android.gms.common.GooglePlayServicesClient
|
Specify <
as the account name to indicate that the default account
on the device should be used.
Bundle key for specifying which user's app activity (moment) types can be written to Google.
The list of activity types are represented as a space-separated string passed in the extras
Bundle when calling ERROR(/GoogleAuthUtil#getToken(Context, String, String, Bundle))
.
This bundle key should be included in the extras Bundle when calling
ERROR(/GoogleAuthUtil#getToken(Context, String, String, Bundle))
and should only be used when
requesting the PLUS_LOGIN
OAuth 2.0 scope.
See Types of moments
for the full list of valid activity types. Example usage:
Bundle bundle = new Bundle(); bundle.putString(PlusClient.KEY_REQUEST_VISIBLE_ACTIVITIES, "http://schemas.google.com/AddActivity http://schemas.google.com/BuyActivity"); String token = GoogleAuthUtil.getToken(context, accountName, Scopes.PLUS_LOGIN, bundle);
Clears the default account for this PlusClient
instance. Use this method to allow
the user to choose a different account the next time connect()
is called.
This operation doesn't affect existing connected instances of PlusClient
. This
client and any others will continue to use the same account. You should call
disconnect()
and connect()
if you want
to reset the account.
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()
is called. On a failure,
onConnectionFailed(ConnectionResult)
is called.
Closes the connection to Google Play services. No calls can be made on this object after calling this method.
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.
SecurityException | If your app doesn't have the
GET_ACCOUNTS permission.
|
---|
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
constructor.
This method can return null
if the required scopes weren't specified in the
PlusClient
constructor, or if there was a network error while connecting.
null
otherwise.
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 specified listener is currently registered to receive connection events.
listener | The listener to check for. |
---|
Returns true if the specified listener is currently registered to receive connection failed events.
listener | The listener to check for. |
---|
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
constructor.
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. |
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
constructor.
listener | The PlusClient.OnMomentsLoadedListener to receive a callback when the moments
are loaded.
|
---|
Loads a list of people in the specified collection. 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
loadPerson(OnPersonLoadedListener, String)
method.
This method requires the PLUS_LOGIN
OAuth 2.0 scope specified in the
PlusClient
constructor.
listener | The PlusClient.OnPeopleLoadedListener to receive a callback when the people
are loaded. |
---|---|
collection | The collection of people to list. Valid values include:
VISIBLE - The list of people who this user has added
to one or more circles. |
orderBy | The order to return people in. Valid values are:
|
maxResults | The maximum number of people 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. |
Loads a list of people in the specified collection. 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
loadPerson(OnPersonLoadedListener, String)
method.
This method requires the PLUS_LOGIN
OAuth 2.0 scope specified in the
PlusClient
constructor.
listener | The PlusClient.OnPeopleLoadedListener to receive a callback when the people
are loaded. |
---|---|
collection | The collection of people to list. Valid values include:
|
Loads profile information for a specified Google+ 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
constructor.
listener | The PlusClient.OnPersonLoadedListener to receive a callback when the person
is loaded. |
---|---|
userId | The ID of the person to get the profile for. The special value "me" can be used to indicate the authenticated user. |
Registers a listener to receive connection events from this GooglePlayServicesClient
.
If we are already connected, the listener's onConnected()
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()
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.
listener | the listener where the results of the asynchronous connect() call are
delivered.
|
---|
Registers a listener to receive connection failed events from this
GooglePlayServicesClient
. Unlike registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks)
, if we are 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.
listener | the listener where the results of the asynchronous connect() call are
delivered.
|
---|
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
constructor.
momentId | The ID of the moment to delete. |
---|
Revokes access given to the current application. The current PlusClient
will be
disconnected when the PlusClient.OnAccessRevokedListener
receives a callback.
listener | The PlusClient.OnAccessRevokedListener to receive a callback when the token
is revoked.
|
---|
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.
listener | the listener to unregister. |
---|
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.
listener | the listener to unregister. |
---|
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
constructor.
moment | The moment description. |
---|