Package oauth2client :: Module client :: Class GoogleCredentials
[hide private]
[frames] | no frames]

Class GoogleCredentials

source code


Application Default Credentials for use in calling Google APIs.

The Application Default Credentials are being constructed as a function of
the environment where the code is being run.
More details can be found on this page:
https://developers.google.com/accounts/docs/application-default-credentials

Here is an example of how to use the Application Default Credentials for a
service that requires authentication:

<code>
from __future__ import print_function  # unnecessary in python3
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials

PROJECT = 'bamboo-machine-422'  # replace this with one of your projects
ZONE = 'us-central1-a'          # replace this with the zone you care about

credentials = GoogleCredentials.get_application_default()
service = build('compute', 'v1', credentials=credentials)

request = service.instances().list(project=PROJECT, zone=ZONE)
response = request.execute()

print(response)
</code>

A service that does not require authentication does not need credentials
to be passed in:

<code>
from googleapiclient.discovery import build

service = build('discovery', 'v1')

request = service.apis().list()
response = request.execute()

print(response)
</code>

Instance Methods [hide private]
 
__init__(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent, revoke_uri=GOOGLE_REVOKE_URI)
Create an instance of GoogleCredentials.
source code
 
create_scoped_required(self)
Whether this Credentials object is scopeless.
source code
 
create_scoped(self, scopes)
Create a Credentials object for the given scopes.
source code
 
serialization_data(self)
Get the fields and their values identifying the current credentials.
source code

Inherited from OAuth2Credentials: __getstate__, __setstate__, access_token_expired, apply, authorize, get_access_token, refresh, revoke, set_store, to_json

Inherited from Credentials (private): _to_json

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]

Inherited from OAuth2Credentials: from_json

Inherited from Credentials: new_from_json

Static Methods [hide private]
 
get_application_default()
Get the Application Default Credentials for the current environment.
source code
 
from_stream(credential_filename)
Create a Credentials object by reading the information from a given file.
source code
Class Variables [hide private]

Inherited from Credentials: NON_SERIALIZED_MEMBERS

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent, revoke_uri=GOOGLE_REVOKE_URI)
(Constructor)

source code 
Create an instance of GoogleCredentials.

This constructor is not usually called by the user, instead
GoogleCredentials objects are instantiated by
GoogleCredentials.from_stream() or
GoogleCredentials.get_application_default().

Args:
  access_token: string, access token.
  client_id: string, client identifier.
  client_secret: string, client secret.
  refresh_token: string, refresh token.
  token_expiry: datetime, when the access_token expires.
  token_uri: string, URI of token endpoint.
  user_agent: string, The HTTP User-Agent to provide for this application.
  revoke_uri: string, URI for revoke endpoint.
    Defaults to GOOGLE_REVOKE_URI; a token can't be revoked if this is None.

Overrides: object.__init__

create_scoped_required(self)

source code 
Whether this Credentials object is scopeless.

create_scoped(scopes) method needs to be called in order to create
a Credentials object for API calls.

create_scoped(self, scopes)

source code 
Create a Credentials object for the given scopes.

The Credentials type is preserved.

serialization_data(self)

source code 
Get the fields and their values identifying the current credentials.

Decorators:
  • @property

get_application_default()
Static Method

source code 
Get the Application Default Credentials for the current environment.

Exceptions:
  ApplicationDefaultCredentialsError: raised when the credentials fail
                                      to be retrieved.

from_stream(credential_filename)
Static Method

source code 
Create a Credentials object by reading the information from a given file.

It returns an object of type GoogleCredentials.

Args:
  credential_filename: the path to the file from where the credentials
    are to be read

Exceptions:
  ApplicationDefaultCredentialsError: raised when the credentials fail
                                      to be retrieved.