我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用oauth2client.client.AccessTokenCredentials()。
def test_access_token_credentials(self): access_token = 'foo' user_agent = 'refresh_checker/1.0' credentials = client.AccessTokenCredentials(access_token, user_agent) storage = file_module.Storage(FILENAME) credentials = storage.put(credentials) credentials = storage.get() self.assertIsNotNone(credentials) self.assertEquals('foo', credentials.access_token) self.assertTrue(os.path.exists(FILENAME)) if os.name == 'posix': # pragma: NO COVER mode = os.stat(FILENAME).st_mode self.assertEquals('0o600', oct(stat.S_IMODE(mode)))
def get_authenticated_service(self): """ Create youtube oauth2 connection """ credentials = AccessTokenCredentials( access_token=self.get_auth_code(), user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' ) return build( 'youtube', 'v3', http=credentials.authorize(httplib2.Http()) )
def setUp(self): access_token = 'foo' user_agent = 'refresh_checker/1.0' self.credentials = client.AccessTokenCredentials( access_token, user_agent, revoke_uri=oauth2client.GOOGLE_REVOKE_URI)
def _FetchCredentialWithSso(sso_cli, sso_email, scopes): """Fetch a credential with access_token fetched from the sso CLI.""" commands = [sso_cli, sso_email] + scopes try: process = subprocess.Popen( commands, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result, _ = process.communicate() if process.returncode != 0: raise Exception except: raise ValueError('Failed to fetch OAuth token by SSO.') return client.AccessTokenCredentials( result.strip(), _DEFAULT_USER_AGENT)
def get_credentials(googleuser): return client.AccessTokenCredentials(googleuser.access_token, 'web client')
def get_plus_service(googleuser): cred = client.AccessTokenCredentials(googleuser.access_token, 'web client') http_auth = cred.authorize(httplib2.Http()) plus_service = discovery.build('plus', 'v1', http=http_auth) return plus_service