1"Same As Above but it was missing step 8!"
2from oauth2client.service_account import ServiceAccountCredentials
3import gspread
4
5scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive',
6 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/spreadsheets']
7
8#Generate a json file by using service account auth in google developer console
9'''
10Link: https://console.developers.google.com/
111) Enable API Access for a Project if you haven’t done it yet.
122) Go to “APIs & Services > Credentials” and choose “Create credentials > Service account key”.
133) Fill out the form
144) Click “Create” and “Done”.
155) Press “Manage service accounts” above Service Accounts.
166) Press on ⋮ near recently created service account and select “Manage keys” and then click on “ADD KEY > Create new key”.
177) Select JSON key type and press “Create”.
188) Go to the google sheet and share the sheet with the email from service accounts.
19'''
20creds = ServiceAccountCredentials.from_json_keyfile_name('mod.json', scope)
21client = gspread.authorize(creds)
22
23sheet = client.open_by_url("#Paste yout google sheet url here").sheet1
24
25data = sheet.get_all_records()
26
27sheet.update_cell(1, 1, "You made it") #Write this message in first row and first column
28
29print(data)
1# see the source first and follow the instuctions on it before running this script
2#
3
4import pygsheets
5import pandas as pd
6#authorization
7gc = pygsheets.authorize(service_file='/Users/erikrood/desktop/QS_Model/creds.json')
8
9# Create empty dataframe
10df = pd.DataFrame()
11
12# Create a column
13df['name'] = ['John', 'Steve', 'Sarah']
14
15#open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet)
16sh = gc.open('PY to Gsheet Test')
17
18#select the first sheet
19wks = sh[0]
20
21#update the first sheet with df, starting at cell B2.
22wks.set_dataframe(df,(1,1))
23
1from oauth2client.service_account import ServiceAccountCredentials
2import gspread
3
4scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive',
5 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/spreadsheets']
6
7#Generate a json file by using service account auth in google developer console
8'''
9Link: https://console.developers.google.com/
101) Enable API Access for a Project if you haven’t done it yet.
112) Go to “APIs & Services > Credentials” and choose “Create credentials > Service account key”.
123) Fill out the form
134) Click “Create” and “Done”.
145) Press “Manage service accounts” above Service Accounts.
156) Press on ⋮ near recently created service account and select “Manage keys” and then click on “ADD KEY > Create new key”.
167) Select JSON key type and press “Create”.
17'''
18creds = ServiceAccountCredentials.from_json_keyfile_name('mod.json', scope)
19client = gspread.authorize(creds)
20
21sheet = client.open_by_url("#Paste yout google sheet url here").sheet1
22
23data = sheet.get_all_records()
24
25sheet.update_cell(1, 1, "You made it") #Write this message in first row and first column
26
27print(data)
28