Play with Google Spread Sheets in python (OAuth)

environment

Preparation

Issuing Google Drive API

Creating a project

スクリーンショット 2016-04-11 22.46.14.png スクリーンショット 2016-04-11 22.45.20.png

API

スクリーンショット 2016-04-11 22.29.31.png スクリーンショット 2016-04-11 22.30.48.png スクリーンショット 2016-04-11 22.36.07.png

Sharing settings on the spreadsheet side

スクリーンショット 2016-04-11 22.53.04.png

url https://docs.google.com/spreadsheets/d/***********/edit The asterisk part becomes id

Python

Library installation

Code


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

Play with Google Spread Sheets in python (OAuth)
Play with 2016-Python
Edit Google Spread Sheets with Python (Low-cost RPA case with Google APIs and Python)
[REAPER] How to play with Reascript in Python
Put text scraped in Python into Google Sheets
Play youtube in python
I tried to access Google Spread Sheets using Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Debugging with pdb in Python
Study Python with Google Colaboratory
Working with sounds in Python
Scraping with Selenium in Python
Scraping with Tor in Python
Tweet with image in Python
[Python] Play with Discord's Webhook.
Combined with permutations in Python
Play RocketChat with API / Python
Access Google Drive with Python
How to extract any appointment in Google Calendar with Python
Play with Mastodon's archive in Python 2 Count replies and favourites
Issue reverse geocoding in Japanese with Python Google Maps API
Call Google G Suite APIs (Sheets / Slides, etc.) with Python
Play with YouTube Data API v3 using Google API Python Client
Testing with random numbers in Python
GOTO in Python with Sublime Text 3
Simple OAuth 2 in Python (urllib + oauthlib)
Working with LibreOffice in Python: import
Scraping with Selenium in Python (Basic)
CSS parsing with cssutils in Python
Numer0n with items made in Python
Open UTF-8 with BOM in Python
Download Google Drive files in Python
Let's play with Excel with Python [Beginner]
Use rospy with virtualenv in Python3
Use Python in pyenv with NeoVim
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
Password generation in texto with python
Use OpenCV with Python 3 in Window
Until dealing with python in Atom
Play with Turtle on Google Colab
Get started with Python in Blender
Working with DICOM images in Python
Write documentation in Sphinx with Python Livereload
Play video with sound with python !! (tkinter / imageio)
Get additional data in LDAP with python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
Python3> in keyword> True with partial match?
Exclusive control with lock file in Python
Install Pyaudio to play wave in python
Play audio files from Python with interrupts
Device monitoring with On-box Python in IOS-XE
Play handwritten numbers with python Part 2 (identify)
Try working with binary data in Python
How to update Google Sheets from Python
How to deal with OAuth2 error when using Google APIs from Python
Draw Nozomi Sasaki in Excel with python
Tips for dealing with binaries in Python
Search and play YouTube videos in Python