【发布时间】:2017-10-10 12:43:36
【问题描述】:
我已设法使用 Google API 打开和编辑现有的 google 表格,但尝试创建新表格时失败:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
from googleapiclient import discovery
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
gc = gspread.authorize(credentials)
service = discovery.build('sheets', 'v4', credentials=credentials)
spreadsheet_body = {
#
}
request = service.spreadsheets().create(body=spreadsheet_body)
response = request.execute()
pprint(response)
上面创建了一个文件,但是当我访问终端中给出的链接时,我需要授予访问权限!终端的输出如下:
{'properties': {'autoRecalc': 'ON_CHANGE',
'defaultFormat': {'backgroundColor': {'blue': 1,
'green': 1,
'red': 1},
'padding': {'bottom': 2,
'left': 3,
'right': 3,
'top': 2},
'textFormat': {'bold': False,
'fontFamily': 'arial,sans,sans-serif',
'fontSize': 10,
'foregroundColor': {},
'italic': False,
'strikethrough': False,
'underline': False},
'verticalAlignment': 'BOTTOM',
'wrapStrategy': 'OVERFLOW_CELL'},
'locale': 'en_US',
'timeZone': 'Etc/GMT',
'title': 'Untitled spreadsheet'},
'sheets': [{'properties': {'gridProperties': {'columnCount': 26,
'rowCount': 1000},
'index': 0,
'sheetId': 0,
'sheetType': 'GRID',
'title': 'Sheet1'}}],
'spreadsheetId': '1bSzXveNHTFDuk6Idj5snsZQVp0RAR-ksb5s_CZusQus',
'spreadsheetUrl': 'https://docs.google.com/spreadsheets/d/1bSzXveNHTFDuk6Idj5snsZQVp0RAR-ksb5s_CZusQus/edit'}
有没有办法解析电子表格 ID 甚至更好.. 其文件夹(目标)并授予特定用户访问权限(通过电子邮件)?
【问题讨论】:
标签: python-3.x google-drive-api google-spreadsheet-api