Documentation

Google_Client
in package

The Google API Client https://github.com/google/google-api-php-client

Table of Contents

API_BASE_PATH  = 'https://www.googleapis.com'
LIBVER  = "2.7.2"
OAUTH2_AUTH_URL  = 'https://accounts.google.com/o/oauth2/auth'
OAUTH2_REVOKE_URI  = 'https://oauth2.googleapis.com/revoke'
OAUTH2_TOKEN_URI  = 'https://oauth2.googleapis.com/token'
USER_AGENT_SUFFIX  = "google-api-php-client/"
$requestedScopes  : array<string|int, mixed>
$auth  : OAuth2
$cache  : CacheItemPoolInterface
$config  : array<string|int, mixed>
$deferExecution  : bool
$http  : ClientInterface
$logger  : LoggerInterface
$token  : array<string|int, mixed>
__construct()  : mixed
Construct the Google Client.
addScope()  : mixed
This functions adds a scope to be requested as part of the OAuth2.0 flow.
authenticate()  : array<string|int, mixed>
For backwards compatibility alias for fetchAccessTokenWithAuthCode
authorize()  : ClientInterface
Adds auth listeners to the HTTP client based on the credentials set in the Google API Client object
createAuthUrl()  : string
Create a URL to obtain user authorization.
execute()  : object
Helper method to execute deferred HTTP requests.
fetchAccessTokenWithAssertion()  : array<string|int, mixed>
Fetches a fresh access token with a given assertion token.
fetchAccessTokenWithAuthCode()  : array<string|int, mixed>
Attempt to exchange a code for an valid authentication token.
fetchAccessTokenWithRefreshToken()  : array<string|int, mixed>
Fetches a fresh OAuth 2.0 access token with the given refresh token.
getAccessToken()  : mixed
getAuth()  : mixed
getCache()  : CacheItemPoolInterface
getClientId()  : mixed
getClientSecret()  : mixed
getConfig()  : mixed
getHttpClient()  : ClientInterface
getLibraryVersion()  : string
Get a string containing the version of the library.
getLogger()  : LoggerInterface
getOAuth2Service()  : OAuth2
getRedirectUri()  : mixed
getRefreshToken()  : string|null
getScopes()  : array<string|int, mixed>
Returns the list of scopes requested by the client
isAccessTokenExpired()  : bool
Returns if the access_token is expired.
isAppEngine()  : mixed
Are we running in Google AppEngine? return bool
isUsingApplicationDefaultCredentials()  : mixed
To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional
prepareScopes()  : string|null
refreshToken()  : array<string|int, mixed>
For backwards compatibility alias for fetchAccessTokenWithRefreshToken
refreshTokenWithAssertion()  : array<string|int, mixed>
For backwards compatibility alias for fetchAccessTokenWithAssertion
revokeToken()  : bool
Revoke an OAuth2 access token or refresh token. This method will revoke the current access token, if a token isn't provided.
setAccessToken()  : mixed
Set the access token used for requests.
setAccessType()  : mixed
setApiFormatV2()  : mixed
Set the API format version.
setApplicationName()  : mixed
Set the application name, this is included in the User-Agent HTTP header.
setApprovalPrompt()  : mixed
setAuth()  : mixed
setAuthConfig()  : mixed
Set the auth config from new or deprecated JSON config.
setAuthConfigFile()  : mixed
For backwards compatibility alias for setAuthConfig
setCache()  : mixed
Set the Cache object
setCacheConfig()  : mixed
setClientId()  : mixed
Set the OAuth 2.0 Client ID.
setClientSecret()  : mixed
Set the OAuth 2.0 Client Secret.
setConfig()  : mixed
setDefer()  : mixed
Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();
setDeveloperKey()  : mixed
Set the developer key to use, these are obtained through the API Console.
setHostedDomain()  : mixed
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.
setHttpClient()  : mixed
Set the Http Client object
setIncludeGrantedScopes()  : mixed
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.
setLogger()  : mixed
Set the Logger object
setLoginHint()  : mixed
Set the login hint, email address or sub id.
setOpenidRealm()  : mixed
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.
setPrompt()  : mixed
Set the prompt hint. Valid values are none, consent and select_account.
setRedirectUri()  : mixed
Set the OAuth 2.0 Redirect URI.
setRequestVisibleActions()  : mixed
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.
setScopes()  : mixed
Set the scopes to be requested. Must be called before createAuthUrl().
setState()  : mixed
Set OAuth 2.0 "state" parameter to achieve per-request customization.
setSubject()  : mixed
Use when the service account has been delegated domain wide access.
setTokenCallback()  : mixed
sets function to be called when an access token is fetched
setUseBatch()  : mixed
Declare whether batch calls should be used. This may increase throughput by making multiple requests in one connection.
shouldDefer()  : bool
Whether or not to return raw requests
useApplicationDefaultCredentials()  : mixed
Set the configuration to use application default credentials for authentication
verifyIdToken()  : array<string|int, mixed>|false
Verify an id_token. This method will verify the current id_token, if one isn't provided.
createDefaultCache()  : mixed
createDefaultHttpClient()  : mixed
createDefaultLogger()  : mixed
createOAuth2Service()  : mixed
create a default google auth object
getAuthHandler()  : mixed
createApplicationDefaultCredentials()  : mixed
createUserRefreshCredentials()  : mixed

Constants

API_BASE_PATH

public mixed API_BASE_PATH = 'https://www.googleapis.com'

LIBVER

public mixed LIBVER = "2.7.2"

OAUTH2_AUTH_URL

public mixed OAUTH2_AUTH_URL = 'https://accounts.google.com/o/oauth2/auth'

OAUTH2_REVOKE_URI

public mixed OAUTH2_REVOKE_URI = 'https://oauth2.googleapis.com/revoke'

OAUTH2_TOKEN_URI

public mixed OAUTH2_TOKEN_URI = 'https://oauth2.googleapis.com/token'

USER_AGENT_SUFFIX

public mixed USER_AGENT_SUFFIX = "google-api-php-client/"

Properties

$requestedScopes

protected array<string|int, mixed> $requestedScopes = []

$config

private array<string|int, mixed> $config

$deferExecution

private bool $deferExecution = alse

$token

private array<string|int, mixed> $token

access token

Methods

__construct()

Construct the Google Client.

public __construct([array<string|int, mixed> $config = array() ]) : mixed
Parameters
$config : array<string|int, mixed> = array()
Return values
mixed —

addScope()

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

public addScope( $scope_or_scopes) : mixed

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"

Return values
mixed —

authenticate()

For backwards compatibility alias for fetchAccessTokenWithAuthCode

public authenticate( $code) : array<string|int, mixed>
Parameters
$code :

string code from accounts.google.com

Tags
deprecated
Return values
array<string|int, mixed> —

access token

createAuthUrl()

Create a URL to obtain user authorization.

public createAuthUrl([string|array<string|int, mixed> $scope = null ]) : string

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

Parameters
$scope : string|array<string|int, mixed> = null

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

Return values
string —

execute()

Helper method to execute deferred HTTP requests.

public execute( $request[, string $expectedClass = null ]) : object
Parameters
$request :

Psr\Http\Message\RequestInterface|Google_Http_Batch

$expectedClass : string = null
Tags
throws
Google_Exception
Return values
object —

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

fetchAccessTokenWithAssertion()

Fetches a fresh access token with a given assertion token.

public fetchAccessTokenWithAssertion([ClientInterface $authHttp = null ]) : array<string|int, mixed>
Parameters
$authHttp : ClientInterface = null

optional.

Return values
array<string|int, mixed> —

access token

fetchAccessTokenWithAuthCode()

Attempt to exchange a code for an valid authentication token.

public fetchAccessTokenWithAuthCode( $code) : array<string|int, mixed>

Helper wrapped around the OAuth 2.0 implementation.

Parameters
$code :

string code from accounts.google.com

Return values
array<string|int, mixed> —

access token

fetchAccessTokenWithRefreshToken()

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

public fetchAccessTokenWithRefreshToken([string $refreshToken = null ]) : array<string|int, mixed>
Parameters
$refreshToken : string = null
Return values
array<string|int, mixed> —

access token

getAccessToken()

public getAccessToken() : mixed
Return values
mixed —

getAuth()

public getAuth() : mixed
Tags
deprecated

See UPGRADING.md for more information

Return values
mixed —

getClientId()

public getClientId() : mixed
Return values
mixed —

getClientSecret()

public getClientSecret() : mixed
Return values
mixed —

getConfig()

public getConfig(mixed $name[, mixed $default = null ]) : mixed
Parameters
$name : mixed
$default : mixed = null
Return values
mixed —

getLibraryVersion()

Get a string containing the version of the library.

public getLibraryVersion() : string
Return values
string —

getOAuth2Service()

public getOAuth2Service() : OAuth2
Return values
OAuth2 —

implementation

getRedirectUri()

public getRedirectUri() : mixed
Return values
mixed —

getRefreshToken()

public getRefreshToken() : string|null
Return values
string|null —

getScopes()

Returns the list of scopes requested by the client

public getScopes() : array<string|int, mixed>
Return values
array<string|int, mixed> —

the list of scopes

isAccessTokenExpired()

Returns if the access_token is expired.

public isAccessTokenExpired() : bool
Return values
bool —

Returns True if the access_token is expired.

isAppEngine()

Are we running in Google AppEngine? return bool

public isAppEngine() : mixed
Return values
mixed —

prepareScopes()

public prepareScopes() : string|null
Tags
visible

For Testing

Return values
string|null —

refreshToken()

For backwards compatibility alias for fetchAccessTokenWithRefreshToken

public refreshToken(string $refreshToken) : array<string|int, mixed>
Parameters
$refreshToken : string
Return values
array<string|int, mixed> —

access token

refreshTokenWithAssertion()

For backwards compatibility alias for fetchAccessTokenWithAssertion

public refreshTokenWithAssertion() : array<string|int, mixed>
Tags
deprecated
Return values
array<string|int, mixed> —

access token

revokeToken()

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

public revokeToken([string|array<string|int, mixed>|null $token = null ]) : bool
Parameters
$token : string|array<string|int, mixed>|null = null

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

Return values
bool —

Returns True if the revocation was successful, otherwise False.

setAccessToken()

Set the access token used for requests.

public setAccessToken(string|array<string|int, mixed> $token) : mixed

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
$token : string|array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
mixed —

setAccessType()

public setAccessType(string $accessType) : mixed
Parameters
$accessType : string

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

Return values
mixed —

setApiFormatV2()

Set the API format version.

public setApiFormatV2(bool $value) : mixed

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

Parameters
$value : bool
Return values
mixed —

setApplicationName()

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

public setApplicationName(string $applicationName) : mixed
Parameters
$applicationName : string
Return values
mixed —

setApprovalPrompt()

public setApprovalPrompt(string $approvalPrompt) : mixed
Parameters
$approvalPrompt : string

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

Return values
mixed —

setAuth()

public setAuth(mixed $auth) : mixed
Parameters
$auth : mixed
Tags
deprecated

See UPGRADING.md for more information

Return values
mixed —

setAuthConfig()

Set the auth config from new or deprecated JSON config.

public setAuthConfig(string|array<string|int, mixed> $config) : mixed

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

Parameters
$config : string|array<string|int, mixed>

the configuration json

Tags
throws
Google_Exception
Return values
mixed —

setAuthConfigFile()

For backwards compatibility alias for setAuthConfig

public setAuthConfigFile(string $file) : mixed
Parameters
$file : string

the configuration file

Tags
throws
Google_Exception
deprecated
Return values
mixed —

setCacheConfig()

public setCacheConfig(array<string|int, mixed> $cacheConfig) : mixed
Parameters
$cacheConfig : array<string|int, mixed>
Return values
mixed —

setClientId()

Set the OAuth 2.0 Client ID.

public setClientId(string $clientId) : mixed
Parameters
$clientId : string
Return values
mixed —

setClientSecret()

Set the OAuth 2.0 Client Secret.

public setClientSecret(string $clientSecret) : mixed
Parameters
$clientSecret : string
Return values
mixed —

setConfig()

public setConfig(mixed $name, mixed $value) : mixed
Parameters
$name : mixed
$value : mixed
Return values
mixed —

setDefer()

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

public setDefer(bool $defer) : mixed
Parameters
$defer : bool

True if calls should not be executed right away.

Return values
mixed —

setHostedDomain()

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.

public setHostedDomain( $hd) : mixed
Parameters
$hd :

string - the domain to use.

Return values
mixed —

setIncludeGrantedScopes()

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.

public setIncludeGrantedScopes( $include) : mixed
Parameters
$include :

boolean - the URL-space to use.

Return values
mixed —

setLoginHint()

Set the login hint, email address or sub id.

public setLoginHint(string $loginHint) : mixed
Parameters
$loginHint : string
Return values
mixed —

setOpenidRealm()

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.

public setOpenidRealm( $realm) : mixed
Parameters
$realm :

string - the URL-space to use.

Return values
mixed —

setPrompt()

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

public setPrompt( $prompt) : mixed

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

Parameters
$prompt :

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

Return values
mixed —

setRedirectUri()

Set the OAuth 2.0 Redirect URI.

public setRedirectUri(string $redirectUri) : mixed
Parameters
$redirectUri : string
Return values
mixed —

setRequestVisibleActions()

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.

public setRequestVisibleActions(array<string|int, mixed> $requestVisibleActions) : mixed

You can find a list of available types here:

Parameters
$requestVisibleActions : array<string|int, mixed>

Array of app activity types

Tags
link
https://developers.google.com/+/api/moment-types
Return values
mixed —

setScopes()

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

public setScopes(mixed $scope_or_scopes) : mixed

Will remove any previously configured scopes.

Parameters
$scope_or_scopes : mixed
Return values
mixed —

setSubject()

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

public setSubject(string $subject) : mixed
Parameters
$subject : string

an email address account to impersonate

Return values
mixed —

setTokenCallback()

sets function to be called when an access token is fetched

public setTokenCallback(callable $tokenCallback) : mixed
Parameters
$tokenCallback : callable
  • function ($cacheKey, $accessToken)
Return values
mixed —

setUseBatch()

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

public setUseBatch(bool $useBatch) : mixed
Parameters
$useBatch : bool

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

Return values
mixed —

shouldDefer()

Whether or not to return raw requests

public shouldDefer() : bool
Return values
bool —

verifyIdToken()

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

public verifyIdToken([string|null $idToken = null ]) : array<string|int, mixed>|false
Parameters
$idToken : string|null = null

The token (id_token) that should be verified.

Tags
throws
LogicException

If no token was provided and no token was set using setAccessToken.

throws
UnexpectedValueException

If the token is not a valid JWT.

Return values
array<string|int, mixed>|false —

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

createDefaultCache()

protected createDefaultCache() : mixed
Return values
mixed —

createDefaultHttpClient()

protected createDefaultHttpClient() : mixed
Return values
mixed —

createDefaultLogger()

protected createDefaultLogger() : mixed
Return values
mixed —

createOAuth2Service()

create a default google auth object

protected createOAuth2Service() : mixed
Return values
mixed —

getAuthHandler()

protected getAuthHandler() : mixed
Return values
mixed —

createApplicationDefaultCredentials()

private createApplicationDefaultCredentials() : mixed
Return values
mixed —

createUserRefreshCredentials()

private createUserRefreshCredentials(mixed $scope, mixed $refreshToken) : mixed
Parameters
$scope : mixed
$refreshToken : mixed
Return values
mixed —

Search results