Skip to content

Instantly share code, notes, and snippets.

@ikemo3 ikemo3/ Secret
Created Aug 27, 2019

What would you like to do?
Google Sheets APIの例
import httplib2
from googleapiclient import discovery
from oauth2client.service_account import ServiceAccountCredentials
CREDENTIALS_FILE = "credentials.json"
def get_credentials():
return ServiceAccountCredentials.from_json_keyfile_name(CREDENTIALS_FILE, SCOPES)
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
discovery_url = '$discovery/rest?version=v4'
service ='sheets', 'v4', http=http, discoveryServiceUrl=discovery_url)
values = [
"8", "2", "3"
body = {
"values": values
range_name = "A:C"
value_input_option = "USER_ENTERED"
sheet = service.spreadsheets()
sheet.values().append(spreadsheetId=SPREADSHEET_ID, range=range_name, valueInputOption=value_input_option,
insertDataOption="INSERT_ROWS", body=body).execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.