Skip to content

Instantly share code, notes, and snippets.

@Derrick-Sherrill
Created March 29, 2022 21:55
Show Gist options
  • Save Derrick-Sherrill/9e6f22dc390d8c23f9cd04aae61ed614 to your computer and use it in GitHub Desktop.
Save Derrick-Sherrill/9e6f22dc390d8c23f9cd04aae61ed614 to your computer and use it in GitHub Desktop.
Code from Google sheets api
from __future__ import print_function
import os.path
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google.oauth2 import service_account
# Creating Google Sheets Scopes
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'keys.json'
credentials = None
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
# The ID and range of a sample spreadsheet.
SAMPLE_SPREADSHEET_ID = '1hGbo9Kmctpew6J8QqxL97lvHssNQyWH2iY8pypM87z8'
# Create service and call it
service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID, range="sample!A1:B39").execute()
values = result.get('values', [])
for row in values:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment