class Google_Client extends Client (View source)

Constants

LIBVER

USER_AGENT_SUFFIX

OAUTH2_REVOKE_URI

OAUTH2_TOKEN_URI

OAUTH2_AUTH_URL

API_BASE_PATH

Properties

protected $requestedScopes from Client

Methods

__construct(array $config = [])

Construct the Google Client.

from Client
string
getLibraryVersion()

Get a string containing the version of the library.

from Client
array
authenticate(string $code) deprecated

For backwards compatibility alias for fetchAccessTokenWithAuthCode

from Client
array
fetchAccessTokenWithAuthCode(string $code)

Attempt to exchange a code for an valid authentication token.

from Client
array
refreshTokenWithAssertion() deprecated

For backwards compatibility alias for fetchAccessTokenWithAssertion

from Client
array
fetchAccessTokenWithAssertion(ClientInterface $authHttp = null)

Fetches a fresh access token with a given assertion token.

from Client
array
refreshToken(string $refreshToken)

For backwards compatibility alias for fetchAccessTokenWithRefreshToken

from Client
array
fetchAccessTokenWithRefreshToken(string $refreshToken = null)

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

from Client
string
createAuthUrl(string|array $scope = null, array $queryParams = [])

Create a URL to obtain user authorization.

from Client
ClientInterface
authorize(ClientInterface $http = null)

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

from Client
useApplicationDefaultCredentials(boolean $useAppCreds = true)

Set the configuration to use application default credentials for authentication

from Client
isUsingApplicationDefaultCredentials()

To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional

from Client
setAccessToken(string|array $token)

Set the access token used for requests.

from Client
getAccessToken()

No description

from Client
string|null
getRefreshToken()

No description

from Client
bool
isAccessTokenExpired()

Returns if the access_token is expired.

from Client
getAuth() deprecated

No description

from Client
setAuth($auth) deprecated

No description

from Client
setClientId(string $clientId)

Set the OAuth 2.0 Client ID.

from Client
getClientId()

No description

from Client
setClientSecret(string $clientSecret)

Set the OAuth 2.0 Client Secret.

from Client
getClientSecret()

No description

from Client
setRedirectUri(string $redirectUri)

Set the OAuth 2.0 Redirect URI.

from Client
getRedirectUri()

No description

from Client
setState(string $state)

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

from Client
setAccessType(string $accessType)

No description

from Client
setApprovalPrompt(string $approvalPrompt)

No description

from Client
setLoginHint(string $loginHint)

Set the login hint, email address or sub id.

from Client
setApplicationName(string $applicationName)

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

from Client
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.

from Client
setDeveloperKey(string $developerKey)

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

from Client
setHostedDomain(string $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.

from Client
setPrompt(string $prompt)

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

from Client
setOpenidRealm(string $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.

from Client
setIncludeGrantedScopes(bool $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.

from Client
setTokenCallback(callable $tokenCallback)

sets function to be called when an access token is fetched

from Client
boolean
revokeToken(string|array|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.

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

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

from Client
setScopes($scope_or_scopes)

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

from Client
addScope(string|string[] $scope_or_scopes)

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

from Client
array
getScopes()

Returns the list of scopes requested by the client

from Client
string|null
prepareScopes()

No description

from Client
mixed|T|ResponseInterface
execute(RequestInterface $request, class-string|false|null $expectedClass = null)

Helper method to execute deferred HTTP requests.

from Client
setUseBatch(boolean $useBatch)

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

from Client
isAppEngine()

Are we running in Google AppEngine? return bool

from Client
setConfig($name, $value)

No description

from Client
getConfig($name, $default = null)

No description

from Client
setAuthConfigFile(string $file) deprecated

For backwards compatibility alias for setAuthConfig

from Client
setAuthConfig(string|array $config)

Set the auth config from new or deprecated JSON config.

from Client
setSubject(string $subject)

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

from Client
setDefer(boolean $defer)

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

from Client
boolean
shouldDefer()

Whether or not to return raw requests

from Client
OAuth2
getOAuth2Service()

No description

from Client
createOAuth2Service()

create a default google auth object

from Client
setCache(CacheItemPoolInterface $cache)

Set the Cache object

from Client
CacheItemPoolInterface
getCache()

No description

from Client
setCacheConfig(array $cacheConfig)

No description

from Client
setLogger(LoggerInterface $logger)

Set the Logger object

from Client
LoggerInterface
getLogger()

No description

from Client
createDefaultLogger()

No description

from Client
createDefaultCache()

No description

from Client
setHttpClient(ClientInterface $http)

Set the Http Client object

from Client
ClientInterface
getHttpClient()

No description

from Client
setApiFormatV2(bool $value)

Set the API format version.

from Client
createDefaultHttpClient()

No description

from Client
getAuthHandler()

No description

from Client

Details

__construct(array $config = [])

Construct the Google Client.

Parameters

array $config

string getLibraryVersion()

Get a string containing the version of the library.

Return Value

string

array authenticate(string $code) deprecated

deprecated

For backwards compatibility alias for fetchAccessTokenWithAuthCode

Parameters

string $code string code from accounts.google.com

Return Value

array access token

array fetchAccessTokenWithAuthCode(string $code)

Attempt to exchange a code for an valid authentication token.

Helper wrapped around the OAuth 2.0 implementation.

Parameters

string $code code from accounts.google.com

Return Value

array access token

array refreshTokenWithAssertion() deprecated

deprecated

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 optional.

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, array $queryParams = [])

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.
array $queryParams Querystring params to add to the authorization URL.

Return Value

string

ClientInterface authorize(ClientInterface $http = 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.

Return Value

ClientInterface the http client object

useApplicationDefaultCredentials(boolean $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)

Set the access token used for requests.

Note that at the time requests are sent, tokens are cached. A token will be cached for each combination of service and authentication scopes. If a cache pool is not provided, creating a new instance of the client will allow modification of access tokens. If a persistent cache pool is provided, in order to change the access token, you must clear the cached token by calling $client->getCache()->clear(). (Use caution in this case, as calling clear() will remove all cache items, including any items not related to Google API PHP Client.)

Parameters

string|array $token

Exceptions

InvalidArgumentException

getAccessToken()

string|null getRefreshToken()

Return Value

string|null

bool isAccessTokenExpired()

Returns if the access_token is expired.

Return Value

bool Returns True if the access_token is expired.

getAuth() deprecated

deprecated See UPGRADING.md for more information

setAuth($auth) deprecated

deprecated See UPGRADING.md for more information

Parameters

$auth

setClientId(string $clientId)

Set the OAuth 2.0 Client ID.

Parameters

string $clientId

getClientId()

setClientSecret(string $clientSecret)

Set the OAuth 2.0 Client Secret.

Parameters

string $clientSecret

getClientSecret()

setRedirectUri(string $redirectUri)

Set the OAuth 2.0 Redirect URI.

Parameters

string $redirectUri

getRedirectUri()

setState(string $state)

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

setAccessType(string $accessType)

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)

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(string $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

string $hd the domain to use.

setPrompt(string $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

string $prompt {@code "none"} Do not display any authentication or consent screens. Must not be specified with other values. {@code "consent"} Prompt the user for consent. {@code "select_account"} Prompt the user to select an account.

setOpenidRealm(string $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

string $realm the URL-space to use.

setIncludeGrantedScopes(bool $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

bool $include 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)

boolean revokeToken(string|array|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|array|null $token The token (access token or a refresh token) that should be revoked.

Return Value

boolean 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 If no token was provided and no token was set using setAccessToken.
UnexpectedValueException If the token is not a valid JWT.

setScopes($scope_or_scopes)

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

Will remove any previously configured scopes.

Parameters

$scope_or_scopes

addScope(string|string[] $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

string|string[] $scope_or_scopes e.g. "profile"

array getScopes()

Returns the list of scopes requested by the client

Return Value

array the list of scopes

string|null prepareScopes()

Return Value

string|null

mixed|T|ResponseInterface execute(RequestInterface $request, class-string|false|null $expectedClass = null)

Helper method to execute deferred HTTP requests.

Parameters

RequestInterface $request
class-string|false|null $expectedClass

Return Value

mixed|T|ResponseInterface

Exceptions

Exception

setUseBatch(boolean $useBatch)

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

Parameters

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

isAppEngine()

Are we running in Google AppEngine? return bool

setConfig($name, $value)

Parameters

$name
$value

getConfig($name, $default = null)

Parameters

$name
$default

setAuthConfigFile(string $file) deprecated

deprecated

For backwards compatibility alias for setAuthConfig

Parameters

string $file the configuration file

Exceptions

Exception

setAuthConfig(string|array $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

string|array $config the configuration json

Exceptions

Exception

setSubject(string $subject)

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

Parameters

string $subject an email address account to impersonate

setDefer(boolean $defer)

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

Parameters

boolean $defer True if calls should not be executed right away.

boolean shouldDefer()

Whether or not to return raw requests

Return Value

boolean

OAuth2 getOAuth2Service()

Return Value

OAuth2 implementation

protected createOAuth2Service()

create a default google auth object

setCache(CacheItemPoolInterface $cache)

Set the Cache object

Parameters

CacheItemPoolInterface $cache

CacheItemPoolInterface getCache()

Return Value

CacheItemPoolInterface

setCacheConfig(array $cacheConfig)

Parameters

array $cacheConfig

setLogger(LoggerInterface $logger)

Set the Logger object

Parameters

LoggerInterface $logger

LoggerInterface getLogger()

Return Value

LoggerInterface

protected createDefaultLogger()

protected createDefaultCache()

setHttpClient(ClientInterface $http)

Set the Http Client object

Parameters

ClientInterface $http

ClientInterface getHttpClient()

Return Value

ClientInterface

setApiFormatV2(bool $value)

Set the API format version.

true will use V2, which may return more useful error messages.

Parameters

bool $value

protected createDefaultHttpClient()

protected getAuthHandler()