我们从Python开源项目中,提取了以下43个代码示例,用于说明如何使用oauth2client.tools.run()。
def auth_stored_credentials(self, client_secrets_file, scopes=[]): """Authorize stored credentials.""" try: import argparse parser = argparse.ArgumentParser(parents=[tools.argparser]) parser.add_argument('args', nargs=argparse.REMAINDER) flags = parser.parse_args() flags.noauth_local_webserver = True except ImportError: flags = None store = Storage(self.credentials_file) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets( client_secrets_file, scopes, ) flow.user_agent = self.app_name if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print 'Saved credentials to ' + self.credentials_file return credentials
def authenticate(flow, storage=None): """ Try to retrieve a valid set of credentials from the token store if possible Otherwise use the given authentication flow to obtain new credentials and return an authenticated http object Parameters ---------- flow : authentication workflow storage: token storage, default None """ http = httplib2.Http() # Prepare credentials, and authorize HTTP object with them. credentials = storage.get() if credentials is None or credentials.invalid: credentials = tools.run(flow, storage) http = credentials.authorize(http) return http
def get_credentials(self): conf_dir = self.get_conf_dir() credential_path = os.path.join(conf_dir, self.event + '_credentials.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: log.warn("No current valid Google credentials. Starting authentication flow...") flow = client.flow_from_clientsecrets(os.path.join(conf_dir, 'client_secret.json'), 'https://www.googleapis.com/auth/calendar') flow.user_agent = "HOTBot" if self.flags: credentials = tools.run_flow(flow, store, self.flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) log.info('Storing credentials to ' + credential_path) return credentials
def get_credentials(self, client_secret_file, scopes, credentials_dir, credentials_file, flags=None): # Create credentials folder, if necessary if not os.path.exists(credentials_dir): os.makedirs(credentials_dir) # Store for credentials file credential_path = os.path.join(credentials_dir, credentials_file) store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(client_secret_file, scopes) flow.user_agent = APPLICATION_NAME if self._flags: credentials = tools.run_flow(flow, store, self._flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) self._logger.debug("Storing credentials to '{}'".format(credential_path)) else: self._logger.debug("Got valid credential from '{}'".format(credential_path)) return credentials # Create a Google Calendar API service object
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ credential_path = os.path.join(SAVED_CREDENTIALS) print(credential_path) store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): home_dir = path.expanduser('~') credential_dir = path.join(home_dir, '.credentials') if not path.exists(credential_dir): makedirs(credential_dir) credential_path = path.join(credential_dir, 'sheets.googleapis.com-python-quickstart.json') store = file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(client_secret_path, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(self, cred_file='client_secret.json'): import os from oauth2client.file import Storage from oauth2client import client home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(cred_file, scope=['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive']) flow.user_agent = self.app_name try: credentials = tools.run_flow(flow, store, self.flags) except: # Needed only for compatibility with Python 2.6 try: credentials = tools.run_flow(flow, store) except: credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ credential_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir,'drive-to-photos.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print 'Storing credentials to ' + credential_path return credentials
def upload_initialise(): INPUTfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),'INPUT.json') if os.path.exists(INPUTfile): with open(INPUTfile,'r') as file : inputs = json.loads(file.read()) if not inputs['Cookie'] or not inputs['X-GUploader-Client-Info'] or not inputs['effective_id'] : print "Enter all required details in INPUT.json file" print "and re run the program\n" print "Refer ReadMe for help.\nProgram now terminates" print " ----------------------------------------------------------" raise SystemExit else : h1['Cookie'] = inputs['Cookie'] h1['X-GUploader-Client-Info'] = inputs['X-GUploader-Client-Info'] global p1 p1= p1.replace('?????',inputs['effective_id'])
def get_credentials(): # taken from https://developers.google.com/google-apps/calendar/quickstart/python global credentials home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): print('Creating', credential_dir) os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'pi_remind.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to', credential_path) return credentials
def initClientSecret(self, path='client_secrets.json'): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ if not j.sal.fs.exists(path, followlinks=True): raise j.exceptions.Input(message="Could not find google secrets file in %s, please dwonload" % path, level=1, source="", tags="", msgpub="") store = Storage(self.secretsFilePath) self._credentials = store.get() if not j.sal.fs.exists(self.secretsFilePath) or not self._credentials or self._credentials.invalid: flow = client.flow_from_clientsecrets(path, SCOPES) flow.user_agent = APPLICATION_NAME self._credentials = tools.run_flow(flow, store) # credentials = tools.run(flow, store) self.logger.info('Storing credentials to ' + self.secretsFilePath)
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'sendEmail.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'admin-reports_v1-python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'drive-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """ Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'quick-add.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'drive-python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir,'academiadasapostas.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'sheets.googleapis.com-python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'gmail-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'sheets.googleapis.com-singer-target.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Laying the groundwork for future functionality, where all the relevant events for a given user is aggregated, and stored in a Google Calender-feed, which is then served to the user. Not an feature complete file, and is not used in production at the momement. Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-credentials.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(FOLDER_NAME + CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + FOLDER_NAME + credential_path) return credentials
def mainFunction(): SCOPES = 'https://www.googleapis.com/auth/calendar' store = file.Storage('storage.json') creds = store.get() if not creds or creds.invalid: flow = client.flow_from_clientsecrets('client_secret.json', SCOPES) creds = tools.run_flow(flow, store, flags) \ if flags else tools.run(flow, store) CAL = build('calendar', 'v3', http=creds.authorize(Http())) events = createEventJSON(instructors, meetingsArr) print(events[0]) for i in events: e = CAL.events().insert(calendarId='primary', sendNotifications=True, body=i).execute() print('''*** %r event added: Start: %s End: %s''' % (e['summary'].encode('utf-8'), e['start']['dateTime'], e['end']['dateTime'])) #Main
def mainFunction(courseName, sectionID): r = requests.get('http://api.umd.io/v0/courses/sections/' + courseName + '-' + sectionID) instructors = r.json()['instructors'][0] meetingsArr = r.json()['meetings'] SCOPES = 'https://www.googleapis.com/auth/calendar' store = file.Storage('storage.json') creds = store.get() if not creds or creds.invalid: flow = client.flow_from_clientsecrets('client_secret.json', SCOPES) creds = tools.run_flow(flow, store, flags) \ if flags else tools.run(flow, store) CAL = build('calendar', 'v3', http=creds.authorize(Http())) coursename = courseName events = createEventJSON(coursename, instructors, meetingsArr) for i in events: e = CAL.events().insert(calendarId='primary', sendNotifications=True, body=i).execute() print('''*** %r event added: Start: %s End: %s''' % (e['summary'].encode('utf-8'), e['start']['dateTime'], e['end']['dateTime']))
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatability with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME #if flags: # credentials = tools.run_flow(flow, store, flags) #else: # Needed only for compatability with Python 2.6 # credentials = tools.run(flow, store) credentials = tools.run(flow,store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(self): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(self.Config.CLIENT_SECRET_FILE, self.Config.SCOPES) flow.user_agent = self.Config.APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'drive-python-googlecloudvisionspeech.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(self): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, self.google_credentials_name) store = oauth2client.file.Storage(credential_path) credentials = store.get() if (not credentials or credentials.invalid) and not self.google_authorized: log.info("requesting credentials to Google Drive") flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME flow.params['access_type'] = 'offline' if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) log.info('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.eventsOrganizer/credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'client_credentials.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'albert-heijn-calendar-sync.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: try: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) except clientsecrets.InvalidClientSecretsError: print('Unable to locate client_secret.json. Please read the readme and make sure you have the' + \ ' file in the webscraper folder') exit() flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-alfred-today.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags, http=HTTP_INSTANCE) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) #, http=HTTP_INSTANCE) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-alfred-today.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials ### days to number
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'calendar-python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def authorize(outh_file='client_secret.json', outh_creds_store=None, outh_nonlocal=False, service_file=None, credentials=None, **client_kwargs): """Login to Google API using OAuth2 credentials. This function instantiates :class:`Client` and performs authentication. :param outh_file: path to outh2 credentials file, or tokens file :param outh_creds_store: path to directory where tokens should be stored 'global' if you want to store in system-wide location None if you want to store in current script directory :param outh_nonlocal: if the authorization should be done in another computer, this will provide a url which when run will ask for credentials :param service_file: path to service credentials file :param credentials: outh2 credentials object :param no_cache: (http client arg) do not ask http client to use a cache in tmp dir, useful for environments where filesystem access prohibited default: False :returns: :class:`Client` instance. """ # @TODO handle exceptions if not credentials: if service_file: with open(service_file) as data_file: data = jload(data_file) print('service_email : '+str(data['client_email'])) credentials = ServiceAccountCredentials.from_json_keyfile_name(service_file, SCOPES) elif outh_file: credentials = get_outh_credentials(client_secret_file=outh_file, credential_dir=outh_creds_store, outh_nonlocal=outh_nonlocal) else: raise AuthenticationError rclient = Client(oauth=credentials, **client_kwargs) return rclient # @TODO
def get_credentials(): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ print ("int cred") home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'sheets.googleapis.com-python-quickstart.json') store = oauth2client.file.Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: print("flag :" + str(flags)) IPython.embed() credentials = tools.run_flow(flow, store, flags) else: # Needed only for compatibility with Python 2.6 credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials
def MoveToGphotos(filename,size,content): global count timestamp_ms = int(time.time() * 1000) p = p1 # MAKES A COPY SO AS NOT TO DISTURB THROUGHT ITERATION OF EACH OBJECT p = p.replace('=====',filename) p = p.replace('@@@@@',str(size)) p = p.replace('+++++',str(timestamp_ms)) p2 = content up = 1 if up == 1: u1 = "https://photos.google.com/_/upload/photos/resumable?authuser=0" # Initial Request to get the Upload - ID from google r = requests.post(u1,headers=h1,data=p) print ' %s | %s | %s |'%((str(count).zfill(3)).ljust(5),filename.ljust(30),str(size).ljust(7)), count=count + 1 try : u2 = json.loads(r.content)['sessionStatus']['externalFieldTransfers'][0]['putInfo']['url'] r2 = requests.post(u2,headers=h2,data=p2) status = json.loads(r2.content)['sessionStatus']['state'] if status == 'FINALIZED' : print '%s'%('SUCCESS'.ljust(12)) else: print '%s'%('FAILED'.ljust(12)) except KeyError: print "Google Photos Authentication Error\n\ Check the Values added in th INPUT.json file\n\ and run the program again"
def get_credentials(self, cred_path): """Gets valid user credentials from storage. If nothing has been stored, or if the stored credentials are invalid, the OAuth2 flow is completed to obtain the new credentials. Returns: Credentials, the obtained credential. """ if not cred_path: home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') if not os.path.exists(credential_dir): try: os.system("sudo mkdir {}".format(credential_dir)) except: os.umask(0) os.makedirs(credential_dir, mode=0o777) else: credential_dir = cred_path credential_path = os.path.join(credential_dir, 'python-quickstart.json') store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(self.secret_file, scope=['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive']) flow.user_agent = self.app_name try: import argparse flags = argparse.ArgumentParser(parents=[tools.argparser], conflict_handler='resolve').parse_args() except ImportError: flags = None try: credentials = tools.run_flow(flow, store, flags) except: # Needed only for compatibility with Python 2.6 try: credentials = tools.run_flow(flow, store) except: credentials = tools.run(flow, store) print('Storing credentials to ' + credential_path) return credentials