使用Python写入谷歌电子表格

She*_*nta 0 python api google-docs google-docs-api python-2.7

我想知道是否有办法使用Python写入谷歌电子表格.找到了python-gdata-client库,安装了所有依赖项.使用下面的代码,但它不起作用

import time
import gdata.spreadsheet.service

email = 'email@gmail.com'
password = 'pwd'
weight = '180'
# Find this value in the url with 'key=XXX' and copy XXX below
spreadsheet_key = 'pRoiw3us3wh1FyEip46wYtW'
# All spreadsheets have worksheets. I think worksheet #1 by default always
# has a value of 'od6'
worksheet_id = 'Sheet1'

spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = email
spr_client.password = password
spr_client.source = 'Example Spreadsheet Writing Application'
spr_client.ProgrammaticLogin()

# Prepare the dictionary to write
dict = {}
dict['date'] = time.strftime('%m/%d/%Y')
dict['time'] = time.strftime('%H:%M:%S')
dict['weight'] = weight
print dict

entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
  print "Insert row succeeded."
else:
  print "Insert row failed."
Run Code Online (Sandbox Code Playgroud)

这是错误说 -

Traceback (most recent call last):
  File "D:/steve/test.py", line 28, in <module>
    entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
  File "C:\Python27\lib\site-packages\gdata\spreadsheet\service.py", line 338, in InsertRow
    converter=gdata.spreadsheet.SpreadsheetsListFromString)
  File "C:\Python27\lib\site-packages\gdata\service.py", line 1235, in Post
    media_source=media_source, converter=converter)
  File "C:\Python27\lib\site-packages\gdata\service.py", line 1346, in PostOrPut
    redirects_remaining - 1, media_source, converter=converter)
  File "C:\Python27\lib\site-packages\gdata\service.py", line 1328, in PostOrPut
    return converter(result_body)
  File "C:\Python27\lib\site-packages\gdata\spreadsheet\__init__.py", line 376, in SpreadsheetsListFromString
    xml_string)
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 92, in optional_warn_function
    return f(*args, **kwargs)
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 126, in CreateClassFromXMLString
    tree = ElementTree.fromstring(xml_string)
  File "<string>", line 124, in XML
ParseError: mismatched tag: line 944, column 4
Run Code Online (Sandbox Code Playgroud)

Ali*_*lik 5

您正在使用自2012年4月20日以来已弃用的ClientLogin方法.看来Google已于2015年5月26日将其关闭.

请改用OAuth2.