- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
经过一周的谷歌搜索和反复试验,我终于得到了我的 Python 脚本,该脚本将一行添加到 Google 电子表格以使用 OAuth2。为了其他可能遭受同样创伤的人的利益,这是我的工作代码:
script_dir = os.path.dirname(os.path.realpath (sys.argv[0]))
private_key = open(script_dir + "\\myClient.pem").read()
ssClient = gdata.spreadsheets.client.SpreadsheetsClient()
credentials = SignedJwtAssertionCredentials(CLIENT_EMAIL, private_key, SCOPE)
http = Http()
http = credentials.authorize(http)
auth2token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
ssClient = auth2token.authorize(ssClient)
ssClient.GetSpreadsheets()
两个注意事项:
gdata.spreadsheet.service.SpreadsheetsService()
,这将不起作用,但可以使用 gdata.spreadsheets.client.SpreadsheetsClient()
这不适用于从 Google Developer Console 下载的 .p12 文件,我需要将其转换为 .pem 文件:
openssl pkcs12 -nodes -nocerts -in myClient.p12 -out myClient.pem
有人可以确认确实没有办法将 SignedJwtAssertionCredentials
与 SpreadsheetsService
一起使用,或者如果有,请解释正确的程序?我几乎尝试了所有我能想到的组合。
谢谢!
最佳答案
我感受到了你的痛苦,我花了一整天的时间试图让我的旧 gdata.spreadsheet.service 代码与 oauth2client.client.SignedJwtAssertionCredentials 一起工作,但仍然没有成功。它不适用于 SpreadsheetsClient 或 SpreadsheetsService,也不适用于将 .p12 转换为 .pem。它看起来可以正常工作(没有身份验证错误消息)但是当执行例如 GetSpreadsheets() 调用时,我得到一个空结果。
找不到任何将旧的 gdata 代码连接到 oauth 的好例子,你上面的代码片段是迄今为止找到的最清晰的代码片段。斗争还在继续。
关于python - 请确认 : SignedJwtAssertionCredentials only works with SpreadsheetsClient, 不是 SpreadsheetsService?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27382231/
经过一周的谷歌搜索和反复试验,我终于得到了我的 Python 脚本,该脚本将一行添加到 Google 电子表格以使用 OAuth2。为了其他可能遭受同样创伤的人的利益,这是我的工作代码: script
出于某种原因,当我尝试使用 Python 中的 Google Spreadsheets API 更新一个单元格时,如下所示: import gdata.spreadsheets.client impo
我是一名优秀的程序员,十分优秀!