Client
in package
The Google API Client https://github.com/google/google-api-php-client
Table of Contents
Constants
- API_BASE_PATH = 'https://www.googleapis.com'
- LIBVER = "2.10.1"
- 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/"
Properties
- $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>
Methods
- __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() : FetchAuthTokenCache
- createUserRefreshCredentials() : mixed
Constants
API_BASE_PATH
public
mixed
API_BASE_PATH
= 'https://www.googleapis.com'
LIBVER
public
mixed
LIBVER
= "2.10.1"
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
= []
$auth
private
OAuth2
$auth
$cache
private
CacheItemPoolInterface
$cache
$config
private
array<string|int, mixed>
$config
$deferExecution
private
bool
$deferExecution
= false
$http
private
ClientInterface
$http
$logger
private
LoggerInterface
$logger
$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()
addScope()
This functions adds a scope to be requested as part of the OAuth2.0 flow.
public
addScope(mixed $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 : mixed
-
string|array e.g. "profile"
authenticate()
For backwards compatibility alias for fetchAccessTokenWithAuthCode
public
authenticate(mixed $code) : array<string|int, mixed>
Parameters
- $code : mixed
-
string code from accounts.google.com
Return values
array<string|int, mixed> —access token
authorize()
Adds auth listeners to the HTTP client based on the credentials set in the Google API Client object
public
authorize([ClientInterface $http = null ]) : ClientInterface
Parameters
- $http : ClientInterface = null
-
the http client object.
Return values
ClientInterface —the http client object
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
stringexecute()
Helper method to execute deferred HTTP requests.
public
execute(mixed $request[, string $expectedClass = null ]) : object
Parameters
- $request : mixed
-
RequestInterface|\Google\Http\Batch
- $expectedClass : string = null
Tags
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(mixed $code) : array<string|int, mixed>
Helper wrapped around the OAuth 2.0 implementation.
Parameters
- $code : mixed
-
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
getAuth()
public
getAuth() : mixed
See UPGRADING.md for more information
getCache()
public
getCache() : CacheItemPoolInterface
Return values
CacheItemPoolInterfacegetClientId()
public
getClientId() : mixed
getClientSecret()
public
getClientSecret() : mixed
getConfig()
public
getConfig(mixed $name[, mixed $default = null ]) : mixed
Parameters
- $name : mixed
- $default : mixed = null
getHttpClient()
public
getHttpClient() : ClientInterface
Return values
ClientInterfacegetLibraryVersion()
Get a string containing the version of the library.
public
getLibraryVersion() : string
Return values
stringgetLogger()
public
getLogger() : LoggerInterface
Return values
LoggerInterfacegetOAuth2Service()
public
getOAuth2Service() : OAuth2
Return values
OAuth2 —implementation
getRedirectUri()
public
getRedirectUri() : mixed
getRefreshToken()
public
getRefreshToken() : string|null
Return values
string|nullgetScopes()
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
isUsingApplicationDefaultCredentials()
To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional
public
isUsingApplicationDefaultCredentials() : mixed
Tags
prepareScopes()
public
prepareScopes() : string|null
Tags
Return values
string|nullrefreshToken()
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>
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
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.
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
setApplicationName()
Set the application name, this is included in the User-Agent HTTP header.
public
setApplicationName(string $applicationName) : mixed
Parameters
- $applicationName : string
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)
setAuth()
public
setAuth(mixed $auth) : mixed
See UPGRADING.md for more information
Parameters
- $auth : 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
setAuthConfigFile()
For backwards compatibility alias for setAuthConfig
public
setAuthConfigFile(string $file) : mixed
Parameters
- $file : string
-
the configuration file
Tags
setCache()
Set the Cache object
public
setCache(CacheItemPoolInterface $cache) : mixed
Parameters
- $cache : CacheItemPoolInterface
setCacheConfig()
public
setCacheConfig(array<string|int, mixed> $cacheConfig) : mixed
Parameters
- $cacheConfig : array<string|int, mixed>
setClientId()
Set the OAuth 2.0 Client ID.
public
setClientId(string $clientId) : mixed
Parameters
- $clientId : string
setClientSecret()
Set the OAuth 2.0 Client Secret.
public
setClientSecret(string $clientSecret) : mixed
Parameters
- $clientSecret : string
setConfig()
public
setConfig(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
- $value : 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.
setDeveloperKey()
Set the developer key to use, these are obtained through the API Console.
public
setDeveloperKey(string $developerKey) : mixed
Parameters
- $developerKey : string
Tags
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(mixed $hd) : mixed
Parameters
- $hd : mixed
-
string - the domain to use.
setHttpClient()
Set the Http Client object
public
setHttpClient(ClientInterface $http) : mixed
Parameters
- $http : ClientInterface
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(mixed $include) : mixed
Parameters
- $include : mixed
-
boolean - the URL-space to use.
setLogger()
Set the Logger object
public
setLogger(LoggerInterface $logger) : mixed
Parameters
- $logger : LoggerInterface
setLoginHint()
Set the login hint, email address or sub id.
public
setLoginHint(string $loginHint) : mixed
Parameters
- $loginHint : string
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(mixed $realm) : mixed
Parameters
- $realm : mixed
-
string - the URL-space to use.
setPrompt()
Set the prompt hint. Valid values are none, consent and select_account.
public
setPrompt(mixed $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 : mixed
-
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.
setRedirectUri()
Set the OAuth 2.0 Redirect URI.
public
setRedirectUri(string $redirectUri) : mixed
Parameters
- $redirectUri : string
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
setScopes()
Set the scopes to be requested. Must be called before createAuthUrl().
public
setScopes(string|array<string|int, mixed> $scope_or_scopes) : mixed
Will remove any previously configured scopes.
Parameters
- $scope_or_scopes : string|array<string|int, mixed>
-
, ie: array( 'https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/moderator' );
setState()
Set OAuth 2.0 "state" parameter to achieve per-request customization.
public
setState(string $state) : mixed
Parameters
- $state : string
Tags
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
setTokenCallback()
sets function to be called when an access token is fetched
public
setTokenCallback(callable $tokenCallback) : mixed
Parameters
- $tokenCallback : callable
-
- function ($cacheKey, $accessToken)
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.
shouldDefer()
Whether or not to return raw requests
public
shouldDefer() : bool
Return values
booluseApplicationDefaultCredentials()
Set the configuration to use application default credentials for authentication
public
useApplicationDefaultCredentials([bool $useAppCreds = true ]) : mixed
Parameters
- $useAppCreds : bool = true
Tags
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
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
createDefaultHttpClient()
protected
createDefaultHttpClient() : mixed
createDefaultLogger()
protected
createDefaultLogger() : mixed
createOAuth2Service()
create a default google auth object
protected
createOAuth2Service() : mixed
getAuthHandler()
protected
getAuthHandler() : mixed
createApplicationDefaultCredentials()
private
createApplicationDefaultCredentials() : FetchAuthTokenCache
Return values
FetchAuthTokenCachecreateUserRefreshCredentials()
private
createUserRefreshCredentials(mixed $scope, mixed $refreshToken) : mixed
Parameters
- $scope : mixed
- $refreshToken : mixed