def __init__(self, service_email=None, private_key=None, user_email=None): """ Handles credentials and builds the google service. :param service_email: String :param private_key: Path :param user_email: String :raise ValueError: """ self._service_email = service_email or settings.GOOGLE_DRIVE_STORAGE_SERVICE_EMAIL self._key = private_key or settings.GOOGLE_DRIVE_STORAGE_KEY kwargs = {} if user_email or settings.GOOGLE_DRIVE_STORAGE_USER_EMAIL: self._user_email = kwargs[ 'sub'] = user_email or settings.GOOGLE_DRIVE_STORAGE_USER_EMAIL credentials = ServiceAccountCredentials( self._service_email, self._key, scope="https://www.googleapis.com/auth/drive", **kwargs) http = httplib2.Http() http = credentials.authorize(http) self._drive_service = build('drive', 'v2', http=http)
def __init__(self, service_email=None, private_key=None, user_email=None): """ Handles credentials and builds the google service. :param service_email: String :param private_key: Path :param user_email: String :raise ValueError: """ self._service_email = service_email or settings.GOOGLE_DRIVE_STORAGE_SERVICE_EMAIL self._key = private_key or settings.GOOGLE_DRIVE_STORAGE_KEY kwargs = {} if user_email or settings.GOOGLE_DRIVE_STORAGE_USER_EMAIL: self._user_email = kwargs['sub'] = user_email or settings.GOOGLE_DRIVE_STORAGE_USER_EMAIL credentials = ServiceAccountCredentials( self._service_email, self._key, scope="https://www.googleapis.com/auth/drive", **kwargs ) http = httplib2.Http() http = credentials.authorize(http) self._drive_service = build('drive', 'v2', http=http)
def api_service(endpoint, version): """ Builds service object to interface with the google api """ with open('data/' + SETTINGS['P12_KEY_FILE']) as f: private_key = f.read() creds = ServiceAccountCredentials(SETTINGS['GSERVEMAIL'], private_key, SETTINGS['SCOPE']) service = build(endpoint, version, http=creds.authorize(Http())) return service