Client
class Client (View source)
The Google API Client https://github.com/google/google-api-php-client
Constants
LIBVER |
|
USER_AGENT_SUFFIX |
|
OAUTH2_REVOKE_URI |
|
OAUTH2_TOKEN_URI |
|
OAUTH2_AUTH_URL |
|
API_BASE_PATH |
|
Properties
protected | $requestedScopes |
Methods
Construct the Google Client.
Get a string containing the version of the library.
For backwards compatibility alias for fetchAccessTokenWithAuthCode
Attempt to exchange a code for an valid authentication token.
For backwards compatibility alias for fetchAccessTokenWithAssertion
Fetches a fresh access token with a given assertion token.
For backwards compatibility alias for fetchAccessTokenWithRefreshToken
Fetches a fresh OAuth 2.0 access token with the given refresh token.
Create a URL to obtain user authorization.
Adds auth listeners to the HTTP client based on the credentials set in the Google API Client object
Set the configuration to use application default credentials for authentication
To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional
Set the access token used for requests.
No description
No description
Returns if the access_token is expired.
Set the OAuth 2.0 Client ID.
No description
Set the OAuth 2.0 Client Secret.
No description
Set the OAuth 2.0 Redirect URI.
No description
Set OAuth 2.0 "state" parameter to achieve per-request customization.
No description
No description
Set the login hint, email address or sub id.
Set the application name, this is included in the User-Agent HTTP header.
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.
Set the developer key to use, these are obtained through the API Console.
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.
Set the prompt hint. Valid values are none, consent and select_account.
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.
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.
sets function to be called when an access token is fetched
Revoke an OAuth2 access token or refresh token. This method will revoke the current access token, if a token isn't provided.
Verify an id_token. This method will verify the current id_token, if one isn't provided.
Set the scopes to be requested. Must be called before createAuthUrl().
This functions adds a scope to be requested as part of the OAuth2.0 flow.
Returns the list of scopes requested by the client
No description
Helper method to execute deferred HTTP requests.
Declare whether batch calls should be used. This may increase throughput by making multiple requests in one connection.
Are we running in Google AppEngine? return bool
No description
No description
Set the auth config from new or deprecated JSON config.
Use when the service account has been delegated domain wide access.
Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();
Whether or not to return raw requests
No description
create a default google auth object
Set the Cache object
No description
No description
Set the Logger object
No description
No description
No description
Set the Http Client object
No description
Set the API format version.
No description
No description
Details
at line 110
__construct(array $config = [])
Construct the Google Client.
at line 220
string
getLibraryVersion()
Get a string containing the version of the library.
at line 233
array
authenticate(string $code)
deprecated
deprecated
For backwards compatibility alias for fetchAccessTokenWithAuthCode
at line 245
array
fetchAccessTokenWithAuthCode(string $code)
Attempt to exchange a code for an valid authentication token.
Helper wrapped around the OAuth 2.0 implementation.
at line 272
array
refreshTokenWithAssertion()
deprecated
deprecated
For backwards compatibility alias for fetchAccessTokenWithAssertion
at line 282
array
fetchAccessTokenWithAssertion(ClientInterface $authHttp = null)
Fetches a fresh access token with a given assertion token.
at line 318
array
refreshToken(string $refreshToken)
For backwards compatibility alias for fetchAccessTokenWithRefreshToken
at line 328
array
fetchAccessTokenWithRefreshToken(string $refreshToken = null)
Fetches a fresh OAuth 2.0 access token with the given refresh token.
at line 363
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.
at line 415
ClientInterface
authorize(ClientInterface $http = null)
Adds auth listeners to the HTTP client based on the credentials set in the Google API Client object
at line 475
useApplicationDefaultCredentials(boolean $useAppCreds = true)
Set the configuration to use application default credentials for authentication
at line 486
isUsingApplicationDefaultCredentials()
To prevent useApplicationDefaultCredentials from inappropriately being called in a conditional
at line 506
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.)
at line 527
getAccessToken()
at line 535
string|null
getRefreshToken()
at line 548
bool
isAccessTokenExpired()
Returns if the access_token is expired.
at line 583
getAuth()
deprecated
deprecated
at line 593
setAuth($auth)
deprecated
deprecated
at line 604
setClientId(string $clientId)
Set the OAuth 2.0 Client ID.
at line 609
getClientId()
at line 618
setClientSecret(string $clientSecret)
Set the OAuth 2.0 Client Secret.
at line 623
getClientSecret()
at line 632
setRedirectUri(string $redirectUri)
Set the OAuth 2.0 Redirect URI.
at line 637
getRedirectUri()
at line 647
setState(string $state)
Set OAuth 2.0 "state" parameter to achieve per-request customization.
at line 657
setAccessType(string $accessType)
at line 667
setApprovalPrompt(string $approvalPrompt)
at line 676
setLoginHint(string $loginHint)
Set the login hint, email address or sub id.
at line 685
setApplicationName(string $applicationName)
Set the application name, this is included in the User-Agent HTTP header.
at line 698
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:
at line 711
setDeveloperKey(string $developerKey)
Set the developer key to use, these are obtained through the API Console.
at line 722
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.
at line 736
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.
at line 747
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.
at line 758
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.
at line 767
setTokenCallback(callable $tokenCallback)
sets function to be called when an access token is fetched
at line 779
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.
at line 796
array|false
verifyIdToken(string|null $idToken = null)
Verify an id_token. This method will verify the current id_token, if one isn't provided.
at line 829
setScopes($scope_or_scopes)
Set the scopes to be requested. Must be called before createAuthUrl().
Will remove any previously configured scopes.
at line 842
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.
at line 858
array
getScopes()
Returns the list of scopes requested by the client
at line 867
string|null
prepareScopes()
at line 885
mixed|T|ResponseInterface
execute(RequestInterface $request, class-string |false|null $expectedClass = null)
Helper method to execute deferred HTTP requests.
at line 933
setUseBatch(boolean $useBatch)
Declare whether batch calls should be used. This may increase throughput by making multiple requests in one connection.
at line 943
isAppEngine()
Are we running in Google AppEngine? return bool
at line 949
setConfig($name, $value)
at line 954
getConfig($name, $default = null)
at line 967
setAuthConfigFile(string $file)
deprecated
deprecated
For backwards compatibility alias for setAuthConfig
at line 980
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.
at line 1026
setSubject(string $subject)
Use when the service account has been delegated domain wide access.
at line 1037
setDefer(boolean $defer)
Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();
at line 1046
boolean
shouldDefer()
Whether or not to return raw requests
at line 1054
OAuth2
getOAuth2Service()
at line 1066
protected
createOAuth2Service()
create a default google auth object
at line 1086
setCache(CacheItemPoolInterface $cache)
Set the Cache object
at line 1094
CacheItemPoolInterface
getCache()
at line 1106
setCacheConfig(array $cacheConfig)
at line 1115
setLogger(LoggerInterface $logger)
Set the Logger object
at line 1123
LoggerInterface
getLogger()
at line 1132
protected
createDefaultLogger()
at line 1145
protected
createDefaultCache()
at line 1154
setHttpClient(ClientInterface $http)
Set the Http Client object
at line 1162
ClientInterface
getHttpClient()
at line 1178
setApiFormatV2(bool $value)
Set the API format version.
true
will use V2, which may return more useful error messages.