\Google_Client

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

Summary

Methods
Properties
Constants
__construct()
getLibraryVersion()
authenticate()
fetchAccessTokenWithAuthCode()
refreshTokenWithAssertion()
fetchAccessTokenWithAssertion()
refreshToken()
fetchAccessTokenWithRefreshToken()
createAuthUrl()
authorize()
useApplicationDefaultCredentials()
isUsingApplicationDefaultCredentials()
setAccessToken()
getAccessToken()
getRefreshToken()
isAccessTokenExpired()
getAuth()
setAuth()
setClientId()
getClientId()
setClientSecret()
getClientSecret()
setRedirectUri()
getRedirectUri()
setState()
setAccessType()
setApprovalPrompt()
setLoginHint()
setApplicationName()
setRequestVisibleActions()
setDeveloperKey()
setHostedDomain()
setPrompt()
setOpenidRealm()
setIncludeGrantedScopes()
setTokenCallback()
revokeToken()
verifyIdToken()
setScopes()
addScope()
getScopes()
prepareScopes()
execute()
setUseBatch()
isAppEngine()
setConfig()
getConfig()
setAuthConfigFile()
setAuthConfig()
setSubject()
setDefer()
shouldDefer()
getOAuth2Service()
setCache()
getCache()
setCacheConfig()
setLogger()
getLogger()
setHttpClient()
getHttpClient()
No public properties found
LIBVER
USER_AGENT_SUFFIX
OAUTH2_REVOKE_URI
OAUTH2_TOKEN_URI
OAUTH2_AUTH_URL
API_BASE_PATH
createOAuth2Service()
createDefaultLogger()
createDefaultCache()
createDefaultHttpClient()
getAuthHandler()
$requestedScopes
N/A
createApplicationDefaultCredentials()
createUserRefreshCredentials()
$auth
$http
$cache
$token
$config
$logger
$deferExecution
N/A

Constants

LIBVER

LIBVER

USER_AGENT_SUFFIX

USER_AGENT_SUFFIX

OAUTH2_REVOKE_URI

OAUTH2_REVOKE_URI

OAUTH2_TOKEN_URI

OAUTH2_TOKEN_URI

OAUTH2_AUTH_URL

OAUTH2_AUTH_URL

API_BASE_PATH

API_BASE_PATH

Properties

$requestedScopes

$requestedScopes : 

Type

$auth

$auth : \Google\Auth\OAuth2

Type

\Google\Auth\OAuth2

$http

$http : \GuzzleHttp\ClientInterface

Type

\GuzzleHttp\ClientInterface

$cache

$cache : \Psr\Cache\CacheItemPoolInterface

Type

\Psr\Cache\CacheItemPoolInterface

$token

$token : array

Type

array — access token

$config

$config : array

Type

array

$logger

$logger : \Google_Logger_Abstract

Type

\Google_Logger_Abstract

$deferExecution

$deferExecution : boolean

Type

boolean

Methods

__construct()

__construct(array  $config = array()) 

Construct the Google Client.

Parameters

array $config

getLibraryVersion()

getLibraryVersion() : string

Get a string containing the version of the library.

Returns

string

authenticate()

authenticate(  $code) : array

For backwards compatibility alias for fetchAccessTokenWithAuthCode

Parameters

$code

string code from accounts.google.com

Returns

array —

access token

fetchAccessTokenWithAuthCode()

fetchAccessTokenWithAuthCode(  $code) : array

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

Returns

array —

access token

refreshTokenWithAssertion()

refreshTokenWithAssertion() : array

For backwards compatibility alias for fetchAccessTokenWithAssertion

Returns

array —

access token

fetchAccessTokenWithAssertion()

fetchAccessTokenWithAssertion(\GuzzleHttp\ClientInterface  $authHttp = null) : array

Fetches a fresh access token with a given assertion token.

Parameters

\GuzzleHttp\ClientInterface $authHttp

Returns

array —

access token

refreshToken()

refreshToken(string  $refreshToken) : array

For backwards compatibility alias for fetchAccessTokenWithRefreshToken

Parameters

string $refreshToken

Returns

array —

access token

fetchAccessTokenWithRefreshToken()

fetchAccessTokenWithRefreshToken(string  $refreshToken = null) : array

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

Parameters

string $refreshToken

Returns

array —

access token

createAuthUrl()

createAuthUrl(string|array  $scope = null) : string

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.

Returns

string

authorize()

authorize(\GuzzleHttp\ClientInterface  $http = null) : \GuzzleHttp\ClientInterface

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

Parameters

\GuzzleHttp\ClientInterface $http

the http client object.

Returns

\GuzzleHttp\ClientInterface —

the http client object

useApplicationDefaultCredentials()

useApplicationDefaultCredentials(boolean  $useAppCreds = true) 

Set the configuration to use application default credentials for authentication

Parameters

boolean $useAppCreds

isUsingApplicationDefaultCredentials()

isUsingApplicationDefaultCredentials() 

To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional

setAccessToken()

setAccessToken(string|array  $token) 

Parameters

string|array $token

Throws

\InvalidArgumentException

getAccessToken()

getAccessToken() 

getRefreshToken()

getRefreshToken() 

isAccessTokenExpired()

isAccessTokenExpired() : boolean

Returns if the access_token is expired.

Returns

boolean —

Returns True if the access_token is expired.

getAuth()

getAuth() 

setAuth()

setAuth(  $auth) 

Parameters

$auth

setClientId()

setClientId(string  $clientId) 

Set the OAuth 2.0 Client ID.

Parameters

string $clientId

getClientId()

getClientId() 

setClientSecret()

setClientSecret(string  $clientSecret) 

Set the OAuth 2.0 Client Secret.

Parameters

string $clientSecret

getClientSecret()

getClientSecret() 

setRedirectUri()

setRedirectUri(string  $redirectUri) 

Set the OAuth 2.0 Redirect URI.

Parameters

string $redirectUri

getRedirectUri()

getRedirectUri() 

setState()

setState(string  $state) 

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

Parameters

string $state

setAccessType()

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()

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()

setLoginHint(string  $loginHint) 

Set the login hint, email address or sub id.

Parameters

string $loginHint

setApplicationName()

setApplicationName(string  $applicationName) 

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

Parameters

string $applicationName

setRequestVisibleActions()

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()

setDeveloperKey(string  $developerKey) 

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

Parameters

string $developerKey

setHostedDomain()

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()

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()

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()

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()

setTokenCallback(callable  $tokenCallback) 

sets function to be called when an access token is fetched

Parameters

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

revokeToken()

revokeToken(string|null  $token = null) : boolean

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.

Returns

boolean —

Returns True if the revocation was successful, otherwise False.

verifyIdToken()

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

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.

Throws

\LogicException

Returns

array|false —

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

setScopes()

setScopes(  $scopes) 

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

Will remove any previously configured scopes.

Parameters

$scopes

addScope()

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"

getScopes()

getScopes() : array

Returns the list of scopes requested by the client

Returns

array —

the list of scopes

prepareScopes()

prepareScopes() : array

Returns

array

execute()

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

Helper method to execute deferred HTTP requests.

Parameters

$request

Psr\Http\Message\RequestInterface|Google_Http_Batch

$expectedClass

Throws

\Google_Exception

Returns

object —

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

setUseBatch()

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()

isAppEngine() 

Are we running in Google AppEngine? return bool

setConfig()

setConfig(  $name,   $value) 

Parameters

$name
$value

getConfig()

getConfig(  $name,   $default = null) 

Parameters

$name
$default

setAuthConfigFile()

setAuthConfigFile(string  $file) 

For backwards compatibility alias for setAuthConfig

Parameters

string $file

the configuration file

Throws

\Google_Exception

setAuthConfig()

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

Throws

\Google_Exception

setSubject()

setSubject(  $subject) 

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

Parameters

$subject

setDefer()

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.

shouldDefer()

shouldDefer() : boolean

Whether or not to return raw requests

Returns

boolean

getOAuth2Service()

getOAuth2Service() : \Google\Auth\OAuth2

Returns

\Google\Auth\OAuth2 —

implementation

setCache()

setCache(\Psr\Cache\CacheItemPoolInterface  $cache) 

Set the Cache object

Parameters

\Psr\Cache\CacheItemPoolInterface $cache

getCache()

getCache() : \Psr\Cache\CacheItemPoolInterface

Returns

\Psr\Cache\CacheItemPoolInterface —

Cache implementation

setCacheConfig()

setCacheConfig(array  $cacheConfig) : \Google\Auth\CacheInterface

Parameters

array $cacheConfig

Returns

\Google\Auth\CacheInterface —

Cache implementation

setLogger()

setLogger(\Psr\Log\LoggerInterface  $logger) 

Set the Logger object

Parameters

\Psr\Log\LoggerInterface $logger

getLogger()

getLogger() : \Psr\Log\LoggerInterface

Returns

\Psr\Log\LoggerInterface —

implementation

setHttpClient()

setHttpClient(\GuzzleHttp\ClientInterface  $http) 

Set the Http Client object

Parameters

\GuzzleHttp\ClientInterface $http

getHttpClient()

getHttpClient() : \GuzzleHttp\ClientInterface

Returns

\GuzzleHttp\ClientInterface —

implementation

createOAuth2Service()

createOAuth2Service() 

create a default google auth object

createDefaultLogger()

createDefaultLogger() 

createDefaultCache()

createDefaultCache() 

createDefaultHttpClient()

createDefaultHttpClient() 

getAuthHandler()

getAuthHandler() 

createApplicationDefaultCredentials()

createApplicationDefaultCredentials() 

createUserRefreshCredentials()

createUserRefreshCredentials(  $scope,   $refreshToken) 

Parameters

$scope
$refreshToken