Creating Google Spreadsheet using Python / Google Data API

Here's how to create the Google Spreadsheet itself.

The following articles were helpful for setting up OAuth and accessing spreadsheets. Accessing spreadsheets from Python using OAuth 2.0

Also, the following was helpful for creating Google Spreadsheet itself. docs_v3_example.py Create new spreadsheet (Google API / Python)

We have confirmed the operation in the environment of Python 2.7.10 and gdata 2.0.18.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from oauth2client.service_account import ServiceAccountCredentials
import gdata.docs.client

# name definitions
APP_NAME = 'GDataDocumentsAPISample'
name_spr = 'Sample Spreadsheet'

# resources for credential
json_key = 'gspread-test.json'
scope = ['https://docs.google.com/feeds']

# create goole data docs client
client = gdata.docs.client.DocsClient(source=APP_NAME)
client.http_client.debug = True
#client.http_client.debug = False

# create credentials
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_key, scope)
auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)

# authorise
auth_token.authorize(client)

# create document as spreadsheet
document = gdata.docs.data.Resource(type='spreadsheet', title=name_spr)
document = client.CreateResource(document)

# add ACL to  spreadsheet
acl_entry = gdata.docs.data.AclEntry(
    scope=gdata.acl.data.AclScope(value='[email protected]', type='user'),
    role=gdata.acl.data.AclRole(value='writer'),
)
client.AddAclEntry(document, acl_entry, send_notifications=False)
			    
print('Created:', document.title.text, document.resource_id.text)

As a little addicted ... The account when executing Oauth is different from your own Google account, [email protected] is the owner, and it is private by default, so you have to set acl_entry on Google Drive Spreadsheet cannot be displayed with.

Recommended Posts

Creating Google Spreadsheet using Python / Google Data API
[Python] Get insight data using Google My Business API
Data acquisition using python googlemap api
Play with YouTube Data API v3 using Google API Python Client
Get Google Fit API data in Python
Get Youtube data in Python using Youtube Data API
Data analysis using Python 0
Data cleaning using Python
[Python] Get all comments using Youtube Data API
Upload JPG file using Google Drive API in Python
Speech transcription procedure using Python and Google Cloud Speech API
Google Drive Api Tips (Python)
Data analysis using python pandas
Inflating text data by retranslation using google translate in Python
[Introduction] Artificial satellite data analysis using Python (Google Colab environment)
Get data from analytics API with Google API Client for python
[Python] I tried collecting data using the API of wikipedia
The story of creating a database using the Google Analytics API
Get Salesforce data using REST API
[Python] Hit the Google Translation API
Try using Pleasant's API (python / FastAPI)
Get Amazon data using Keep API # 1 Get data
Data acquisition memo using Backlog API
Run Ansible from Python using API
Use Google Analytics API from Python
Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!
Collect product information and process data using Rakuten product search API [Python]
Regularly upload files to Google Drive using the Google Drive API in Python
[Python] I tried to get various information using YouTube Data API!
[SEO] Flow / sample code when using Google Analytics API in Python
[Python] Chapter 04-06 Various data structures (creating dictionaries)
Google Cloud Vision API sample for python
Mouse operation using Windows API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Retrieving food data with Amazon API (Python)
Python: Reading JSON data from web API
[Beginner] Python web scraping using Google Colaboratory
I tried using YOUTUBE Data API V3
Try using Python with Google Cloud Functions
Use Google Cloud Vision API from Python
I tried using UnityCloudBuild API from Python
[Python] Various data processing using Numpy arrays
Image collection using Google Custom Search API
FX data collection using OANDA REST API
Awareness of using Aurora Severless Data API
How to display Map using Google Map API (Android)
Data acquisition from analytics API with Google API Client for python Part 2 Web application
Procedure to use TeamGant's WEB API (using python)
Creating training data
Data analysis python
Creating numbering process using python in DynamoDB Local Numbering process
Run Google Analytics API (core v3) in python
Try using the BitFlyer Ligntning API in Python
Get image URL using Flickr API in Python
I tried using the Google Cloud Vision API
Tweet (API 1.1) on Google App Engine for Python
Let's judge emotions using Emotion API in Python
How to get article data using Qiita API
Copy data between Google Keep accounts in Python
[Python3] Let's analyze data using machine learning! (Regression)