class Google_Client (View source)

Constants

LIBVER

USER_AGENT_SUFFIX

OAUTH2_REVOKE_URI

OAUTH2_TOKEN_URI

OAUTH2_AUTH_URL

API_BASE_PATH

Properties

protected array $requestedScopes

Methods

__construct(array $config = array())

Construct the Google Client.

string
getLibraryVersion()

Get a string containing the version of the library.

array
authenticate($code)

For backwards compatibility alias for fetchAccessTokenWithAuthCode

array
fetchAccessTokenWithAuthCode($code)

Attempt to exchange a code for an valid authentication token.

array
refreshTokenWithAssertion()

For backwards compatibility alias for fetchAccessTokenWithAssertion

array
fetchAccessTokenWithAssertion(ClientInterface $authHttp = null)

Fetches a fresh access token with a given assertion token.

array
refreshToken(string $refreshToken)

For backwards compatibility alias for fetchAccessTokenWithRefreshToken

array
fetchAccessTokenWithRefreshToken(string $refreshToken = null)

Fetches a fresh OAuth 2.0 access token with the given refresh token.

string
createAuthUrl(string|array $scope = null)

Create a URL to obtain user authorization.

ClientInterface
authorize(ClientInterface $http = null, ClientInterface $authHttp = null)

Adds auth listeners to the HTTP client based on the credentials set in the Google API Client object

useApplicationDefaultCredentials(bool $useAppCreds = true)

Set the configuration to use application default credentials for authentication

isUsingApplicationDefaultCredentials()

To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional

setAccessToken(string|array $token)

No description

getAccessToken()

No description

getRefreshToken()

No description

bool
isAccessTokenExpired()

Returns if the access_token is expired.

getAuth()

No description

setAuth($auth)

No description

setClientId(string $clientId)

Set the OAuth 2.0 Client ID.

getClientId()

No description

setClientSecret(string $clientSecret)

Set the OAuth 2.0 Client Secret.

getClientSecret()

No description

setRedirectUri(string $redirectUri)

Set the OAuth 2.0 Redirect URI.

getRedirectUri()

No description

setState(string $state)

Set OAuth 2.0 "state" parameter to achieve per-request customization.

setAccessType(string $accessType)

No description

setApprovalPrompt(string $approvalPrompt)

No description

setLoginHint(string $loginHint)

Set the login hint, email address or sub id.

setApplicationName(string $applicationName)

Set the application name, this is included in the User-Agent HTTP header.

setRequestVisibleActions(array $requestVisibleActions)

If 'plus.login' is included in the list of requested scopes, you can use this method to define types of app activities that your app will write.

setDeveloperKey(string $developerKey)

Set the developer key to use, these are obtained through the API Console.

setHostedDomain($hd)

Set the hd (hosted domain) parameter streamlines the login process for Google Apps hosted accounts. By including the domain of the user, you restrict sign-in to accounts at that domain.

setPrompt($prompt)

Set the prompt hint. Valid values are none, consent and select_account.

setOpenidRealm($realm)

openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which an authentication request is valid.

setIncludeGrantedScopes($include)

If this is provided with the value true, and the authorization request is granted, the authorization will include any previous authorizations granted to this user/application combination for other scopes.

setTokenCallback(callable $tokenCallback)

sets function to be called when an access token is fetched

bool
revokeToken(string|null $token = null)

Revoke an OAuth2 access token or refresh token. This method will revoke the current access token, if a token isn't provided.

array|false
verifyIdToken(string|null $idToken = null)

Verify an id_token. This method will verify the current id_token, if one isn't provided.

setScopes($scopes)

Set the scopes to be requested. Must be called before createAuthUrl().

addScope($scope_or_scopes)

This functions adds a scope to be requested as part of the OAuth2.0 flow.

array
getScopes()

Returns the list of scopes requested by the client

array
prepareScopes()

No description

object
execute(RequestInterface $request, $expectedClass = null)

Helper method to execute deferred HTTP requests.

setUseBatch(bool $useBatch)

Declare whether batch calls should be used. This may increase throughput by making multiple requests in one connection.

isAppEngine()

Are we running in Google AppEngine? return bool

setConfig($name, $value)

No description

getConfig($name, $default = null)

No description

setAuthConfigFile(string $file)

For backwards compatibility alias for setAuthConfig

setAuthConfig($config)

Set the auth config from new or deprecated JSON config.

setSubject($subject)

Use when the service account has been delegated domain wide access.

setDefer(bool $defer)

Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();

bool
shouldDefer()

Whether or not to return raw requests

OAuth2
getOAuth2Service()

No description

createOAuth2Service()

create a default google auth object

setCache(CacheItemPoolInterface $cache)

Set the Cache object

CacheItemPoolInterface
getCache()

No description

CacheInterface
setCacheConfig(array $cacheConfig)

No description

setLogger(LoggerInterface $logger)

Set the Logger object

LoggerInterface
getLogger()

No description

createDefaultLogger()

No description

createDefaultCache()

No description

setHttpClient(ClientInterface $http)

Set the Http Client object

ClientInterface
getHttpClient()

No description

createDefaultHttpClient()

No description

getAuthHandler()

No description

Details

__construct(array $config = array())

Construct the Google Client.

Parameters

array $config

string getLibraryVersion()

Get a string containing the version of the library.

Return Value

string

array authenticate($code)

For backwards compatibility alias for fetchAccessTokenWithAuthCode

Parameters

$code

string code from accounts.google.com

Return Value

array

access token

array fetchAccessTokenWithAuthCode($code)

Attempt to exchange a code for an valid authentication token.

Helper wrapped around the OAuth 2.0 implementation.

Parameters

$code

string code from accounts.google.com

Return Value

array

access token

array refreshTokenWithAssertion()

For backwards compatibility alias for fetchAccessTokenWithAssertion

Return Value

array

access token

array fetchAccessTokenWithAssertion(ClientInterface $authHttp = null)

Fetches a fresh access token with a given assertion token.

Parameters

ClientInterface $authHttp

Return Value

array

access token

array refreshToken(string $refreshToken)

For backwards compatibility alias for fetchAccessTokenWithRefreshToken

Parameters

string $refreshToken

Return Value

array

access token

array fetchAccessTokenWithRefreshToken(string $refreshToken = null)

Fetches a fresh OAuth 2.0 access token with the given refresh token.

Parameters

string $refreshToken

Return Value

array

access token

string createAuthUrl(string|array $scope = null)

Create a URL to obtain user authorization.

The authorization endpoint allows the user to first authenticate, and then grant/deny the access request.

Parameters

string|array $scope

The scope is expressed as an array or list of space-delimited strings.

Return Value

string

ClientInterface authorize(ClientInterface $http = null, ClientInterface $authHttp = null)

Adds auth listeners to the HTTP client based on the credentials set in the Google API Client object

Parameters

ClientInterface $http

the http client object.

ClientInterface $authHttp

an http client for authentication.

Return Value

ClientInterface

the http client object

useApplicationDefaultCredentials(bool $useAppCreds = true)

Set the configuration to use application default credentials for authentication

isUsingApplicationDefaultCredentials()

To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional

setAccessToken(string|array $token)

No description

Parameters

string|array $token

Exceptions

InvalidArgumentException

getAccessToken()

No description

getRefreshToken()

No description

bool isAccessTokenExpired()

Returns if the access_token is expired.

Return Value

bool

Returns True if the access_token is expired.

getAuth()

No description

setAuth($auth)

No description

Parameters

$auth

setClientId(string $clientId)

Set the OAuth 2.0 Client ID.

Parameters

string $clientId

getClientId()

No description

setClientSecret(string $clientSecret)

Set the OAuth 2.0 Client Secret.

Parameters

string $clientSecret

getClientSecret()

No description

setRedirectUri(string $redirectUri)

Set the OAuth 2.0 Redirect URI.

Parameters

string $redirectUri

getRedirectUri()

No description

setState(string $state)

Set OAuth 2.0 "state" parameter to achieve per-request customization.

setAccessType(string $accessType)

No description

Parameters

string $accessType

Possible values for access_type include: {@code "offline"} to request offline access from the user. {@code "online"} to request online access from the user.

setApprovalPrompt(string $approvalPrompt)

No description

Parameters

string $approvalPrompt

Possible values for approval_prompt include: {@code "force"} to force the approval UI to appear. {@code "auto"} to request auto-approval when possible. (This is the default value)

setLoginHint(string $loginHint)

Set the login hint, email address or sub id.

Parameters

string $loginHint

setApplicationName(string $applicationName)

Set the application name, this is included in the User-Agent HTTP header.

Parameters

string $applicationName

setRequestVisibleActions(array $requestVisibleActions)

If 'plus.login' is included in the list of requested scopes, you can use this method to define types of app activities that your app will write.

You can find a list of available types here:

Parameters

array $requestVisibleActions

Array of app activity types

setDeveloperKey(string $developerKey)

Set the developer key to use, these are obtained through the API Console.

Parameters

string $developerKey

See also

http://code.google.com/apis/console-help/#generatingdevkeys

setHostedDomain($hd)

Set the hd (hosted domain) parameter streamlines the login process for Google Apps hosted accounts. By including the domain of the user, you restrict sign-in to accounts at that domain.

Parameters

$hd

string - the domain to use.

setPrompt($prompt)

Set the prompt hint. Valid values are none, consent and select_account.

If no value is specified and the user has not previously authorized access, then the user is shown a consent screen.

Parameters

$prompt string

setOpenidRealm($realm)

openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which an authentication request is valid.

Parameters

$realm

string - the URL-space to use.

setIncludeGrantedScopes($include)

If this is provided with the value true, and the authorization request is granted, the authorization will include any previous authorizations granted to this user/application combination for other scopes.

Parameters

$include

boolean - the URL-space to use.

setTokenCallback(callable $tokenCallback)

sets function to be called when an access token is fetched

Parameters

callable $tokenCallback
  • function ($cacheKey, $accessToken)

bool revokeToken(string|null $token = null)

Revoke an OAuth2 access token or refresh token. This method will revoke the current access token, if a token isn't provided.

Parameters

string|null $token

The token (access token or a refresh token) that should be revoked.

Return Value

bool

Returns True if the revocation was successful, otherwise False.

array|false verifyIdToken(string|null $idToken = null)

Verify an id_token. This method will verify the current id_token, if one isn't provided.

Parameters

string|null $idToken

The token (id_token) that should be verified.

Return Value

array|false

Returns the token payload as an array if the verification was successful, false otherwise.

Exceptions

LogicException

setScopes($scopes)

Set the scopes to be requested. Must be called before createAuthUrl().

Will remove any previously configured scopes.

Parameters

$scopes

addScope($scope_or_scopes)

This functions adds a scope to be requested as part of the OAuth2.0 flow.

Will append any scopes not previously requested to the scope parameter. A single string will be treated as a scope to request. An array of strings will each be appended.

Parameters

$scope_or_scopes

string|array e.g. "profile"

array getScopes()

Returns the list of scopes requested by the client

Return Value

array

the list of scopes

array prepareScopes()

No description

Return Value

array

object execute(RequestInterface $request, $expectedClass = null)

Helper method to execute deferred HTTP requests.

Parameters

RequestInterface $request Psr\Http\Message\RequestInterface|Google_Http_Batch
$expectedClass

Return Value

object

of the type of the expected class or Psr\Http\Message\ResponseInterface.

Exceptions

Google_Exception

setUseBatch(bool $useBatch)

Declare whether batch calls should be used. This may increase throughput by making multiple requests in one connection.

Parameters

bool $useBatch

True if the batch support should be enabled. Defaults to False.

isAppEngine()

Are we running in Google AppEngine? return bool

setConfig($name, $value)

No description

Parameters

$name
$value

getConfig($name, $default = null)

No description

Parameters

$name
$default

setAuthConfigFile(string $file)

For backwards compatibility alias for setAuthConfig

Parameters

string $file

the configuration file

Exceptions

Google_Exception

setAuthConfig($config)

Set the auth config from new or deprecated JSON config.

This structure should match the file downloaded from the "Download JSON" button on in the Google Developer Console.

Parameters

$config

Exceptions

Google_Exception

setSubject($subject)

Use when the service account has been delegated domain wide access.

Parameters

$subject

setDefer(bool $defer)

Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();

Parameters

bool $defer

True if calls should not be executed right away.

bool shouldDefer()

Whether or not to return raw requests

Return Value

bool

OAuth2 getOAuth2Service()

No description

Return Value

OAuth2 implementation

protected createOAuth2Service()

create a default google auth object

setCache(CacheItemPoolInterface $cache)

Set the Cache object

Parameters

CacheItemPoolInterface $cache

CacheItemPoolInterface getCache()

No description

Return Value

CacheItemPoolInterface

Cache implementation

CacheInterface setCacheConfig(array $cacheConfig)

No description

Parameters

array $cacheConfig

Return Value

CacheInterface

Cache implementation

setLogger(LoggerInterface $logger)

Set the Logger object

Parameters

LoggerInterface $logger

LoggerInterface getLogger()

No description

Return Value

LoggerInterface implementation

protected createDefaultLogger()

No description

protected createDefaultCache()

No description

setHttpClient(ClientInterface $http)

Set the Http Client object

Parameters

ClientInterface $http

ClientInterface getHttpClient()

No description

Return Value

ClientInterface implementation

protected createDefaultHttpClient()

No description

protected getAuthHandler()

No description