gpt4 book ai didi

python - 请确认 : SignedJwtAssertionCredentials only works with SpreadsheetsClient, 不是 SpreadsheetsService?

转载 作者:行者123 更新时间:2023-11-28 19:20:07 25 4
gpt4 key购买 nike

经过一周的谷歌搜索和反复试验,我终于得到了我的 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()

两个注意事项:

  1. 如果我使用 gdata.spreadsheet.service.SpreadsheetsService(),这将不起作用,但可以使用 gdata.spreadsheets.client.SpreadsheetsClient()
  2. 这不适用于从 Google Developer Console 下载的 .p12 文件,我需要将其转换为 .pem 文件:

    openssl pkcs12 -nodes -nocerts -in myClient.p12 -out myClient.pem

有人可以确认确实没有办法将 SignedJwtAssertionCredentialsSpreadsheetsService 一起使用,或者如果有,请解释正确的程序?我几乎尝试了所有我能想到的组合。

谢谢!

最佳答案

我感受到了你的痛苦,我花了一整天的时间试图让我的旧 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com