API
client_email
field in the downloaded JSON fileurl https://docs.google.com/spreadsheets/d/***********/edit
The asterisk part becomes id
Python
sudo pip install --upgrade oauth2client --ignore-installed six
-gdata (google regular: not used this time)
sudo pip install gdata --ignore-installed six
-gspread (This one seems to be more convenient, so I will use this one this time)
sudo pip install gspread --ignore-installed six
--ignore-installed six
is added at the end.Code
SignedJwtAssertionCredentials
class was used, but in 2016/02 there was Library Update to use ServiceAccountCredentials
. became
import os
import gspread
from oauth2client.service_account import ServiceAccountCredentials
def main():
scope = ['https://spreadsheets.google.com/feeds']
doc_id = 'Your doc id'
path = os.path.expanduser("Path of json file")
credentials = ServiceAccountCredentials.from_json_keyfile_name(path, scope)
client = gspread.authorize(credentials)
gfile = client.open_by_key(doc_id)
worksheet = gfile.sheet1
records = worksheet.get_all_values()
for record in records:
print(record)
if __name__ == '__main__':
main()
Recommended Posts