How to use the oauth2client.service_account.ServiceAccountCredentials.from_json_keyfile_name function in oauth2client

To help you get started, we’ve selected a few oauth2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danimtb / dasshio / habits.py View on Github external
def login_open_sheet(oauth_key_file, spreadsheet):
    """Connect to Google Docs spreadsheet and return the first worksheet."""
    try:
        json_key = json.load(open(oauth_key_file))
        scope = ['https://spreadsheets.google.com/feeds']
        credentials = ServiceAccountCredentials.from_json_keyfile_name(oauth_key_file, scope)

        gc = gspread.authorize(credentials)
        worksheet = gc.open(spreadsheet).sheet1
        return worksheet
    except Exception as ex:
        print('Unable to login and get spreadsheet.  Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!')
        print('Google sheet login failed with error:', ex)
        sys.exit(1)
github kevinwlu / iot / lesson7 / bmp_spreadsheet.py View on Github external
def login_open_sheet(oauth_key_file, spreadsheet):
    """Connect to Google Docs spreadsheet and return the first worksheet."""
    try:
        credentials = ServiceAccountCredentials.from_json_keyfile_name(oauth_key_file, 
                      scopes=['https://spreadsheets.google.com/feeds',
			      'https://www.googleapis.com/auth/drive'])
        gc = gspread.authorize(credentials)
        worksheet = gc.open(spreadsheet).sheet1
        return worksheet
    except Exception as ex:
        print('Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and')
        print('make sure spreadsheet is shared to the client_email address in the OAuth .json file!')
        print('Google sheet login failed with error:', ex)
        sys.exit(1)
github adafruit / Adafruit_Learning_System_Guides / DHT_Google_Spreadsheet / google_spreadsheet.py View on Github external
def login_open_sheet(oauth_key_file, spreadsheet):
    """Connect to Google Docs spreadsheet and return the first worksheet."""
    try:
        scope =  ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
        credentials = ServiceAccountCredentials.from_json_keyfile_name(oauth_key_file, scope)
        gc = gspread.authorize(credentials)
        worksheet = gc.open(spreadsheet).sheet1 # pylint: disable=redefined-outer-name
        return worksheet
    except Exception as ex: # pylint: disable=bare-except, broad-except
        print('Unable to login and get spreadsheet.  Check OAuth credentials, spreadsheet name, \
        and make sure spreadsheet is shared to the client_email address in the OAuth .json file!')
        print('Google sheet login failed with error:', ex)
        sys.exit(1)
github wwoo / tf_face / tf / web / main.py View on Github external
def get_vision_service():
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        os.path.join(resources.__path__[0], 'vapi-acct.json'), SCOPES)
    return discovery.build('vision', 'v1', credentials=credentials)
github google / gov-meetings-made-searchable / index-meeting / worker.py View on Github external
def psCall(reqUrl, postPayload):
	scopesList = ["https://www.googleapis.com/auth/cloud-platform"]
	credentialsObj = ServiceAccountCredentials.from_json_keyfile_name(
		service_account_path,
		scopes = scopesList
	)

	accessToken = "Bearer %s" % credentialsObj.get_access_token().access_token
	headerObj = {
		"authorization": accessToken,
	}

	reqObj = requests.post(
		reqUrl,
		data = json.dumps(postPayload),
		headers = headerObj
	)

	return reqObj.text
github AyumuKasuga / MoneyTrackerBot / storage.py View on Github external
def reauthorize(self):
        scope = ['https://spreadsheets.google.com/feeds']
        credentials = ServiceAccountCredentials.from_json_keyfile_name(
            self.keyfile, scope)
        gc = gspread.authorize(credentials)
        self.spreadsheet = gc.open(self.spreadsheet_name)
github google / crmint / backends / core / workers.py View on Github external
def _ga_setup(self, v='v4'):
    credentials = ServiceAccountCredentials.from_json_keyfile_name(_KEY_FILE)
    service = 'analyticsreporting' if v == 'v4' else 'analytics'
    self._ga_client = build(service, v, credentials=credentials)
github Netflix-Skunkworks / cloudaux / cloudaux / gcp / auth.py View on Github external
:param key_file: path to key file to use. Default is None
    :type key_file: ``str``

    :param scopes: scopes to set.  Default is DEFAUL_SCOPES
    :type scopes: ``list``

    :param user_agent: User Agent string to use in requests. Default is None.
    :type http_auth: ``str`` or None

    :return: HTTPLib2 authorized client.
    :rtype: :class: `HTTPLib2`
    """
    if key_file:
        if not scopes:
            scopes = DEFAULT_SCOPES
        creds = ServiceAccountCredentials.from_json_keyfile_name(key_file,
                                                                 scopes=scopes)
    else:
        creds = GoogleCredentials.get_application_default()
    http = Http()
    if user_agent:
        http = set_user_agent(http, user_agent)
    http_auth = creds.authorize(http)
    return http_auth
github GatorIncubator / gatorgrouper / spreadsheet.py View on Github external
def create_csv():
    """ Pulls data from Google Sheets, writing to the default CSV file """

    file_name = "./" + DEFAULT_CSVFILE
    logging.info(
        "Authenticating to Google Sheets to obtain Google Form data")
    # use creds to create a client to interact with the Google Drive API
    scope = ['https://spreadsheets.google.com/feeds']
    creds = ServiceAccountCredentials.from_json_keyfile_name(
        '$HOME/gatorgrouper/authorizationKey/keyFile.json', scope)
    client = gspread.authorize(creds)

    # Find a workbook by name and open the first sheet
    # Make sure you use the right name here.
    sheet = client.open(DEFAULT_WORKBOOK).sheet1

    # Extract and print all of the values
    list_of_hashes = sheet.get_all_records()

    # Iterates through the list_of_hashes and creates a list of lists with the
    # format ['username', True, False, True]

    logging.info("Creating a list of lists of students")
    formated_list = list()
    for entry in list_of_hashes:
github spinnaker / spinnaker / google / stackdriver_monitoring / stackdriver_client.py View on Github external
def make_client(options):
    credentials_path = options.credentials_path
    http = httplib2.Http()
    http = apiclient.http.set_user_agent(
        http, 'SpinnakerStackdriverAgent/0.001')
    if credentials_path:
      credentials = ServiceAccountCredentials.from_json_keyfile_name(
            credentials_path, scopes=StackdriverClient.WRITE_SCOPE)
    else:
      credentials = GoogleCredentials.get_application_default()

    http = credentials.authorize(http)
    service = apiclient.discovery.build('monitoring', 'v3', http=http)
    return StackdriverClient(service, options)