Python oauth2client.client.AccessTokenCredentials() Examples

The following are 4 code examples of oauth2client.client.AccessTokenCredentials(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oauth2client.client , or try the search function .
Example #1
Source File: google_analytics_hook.py    From google_analytics_plugin with Apache License 2.0 6 votes vote down vote up
def get_service_object(self, name):
        service = GoogleAnalyticsHook._services[name]

        if self.connection.password:
            credentials = AccessTokenCredentials(self.connection.password,
                                                 'Airflow/1.0')
        elif hasattr(self, 'client_secrets'):
            credentials = ServiceAccountCredentials.from_json_keyfile_dict(self.client_secrets,
                                                                           service.scopes)

        elif hasattr(self, 'file_location'):
            credentials = ServiceAccountCredentials.from_json_keyfile_name(self.file_location,
                                                                           service.scopes)
        else:
            raise ValueError('No valid credentials could be found')

        return build(service.name, service.version, credentials=credentials) 
Example #2
Source File: test_file.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
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))) 
Example #3
Source File: youtube.py    From Zoom2Youtube with MIT License 5 votes vote down vote up
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())
        ) 
Example #4
Source File: get-gdrive-appdata.py    From gdrive-appdata with Apache License 2.0 5 votes vote down vote up
def get_gdrive_credentials(gms_ctx, app_id, app_sig):
    gdrive_token = get_gdrive_access_token(gms_ctx, app_id, app_sig)
    print(('GDrive token: %s' % gdrive_token))
    if gdrive_token is None:
        return None

    cred = client.AccessTokenCredentials(gdrive_token, 'Mozilla/5.0 compatible')
    cred.scopes.add(DRIVE_FILE)
    cred.scopes.add(DRIVE_APPDATA)
    
    return cred