gdata - 电子表格列表 Gdata OAuth2

标签 gdata google-oauth google-spreadsheet-api google-apps-marketplace

在 Gdata 中使用电子表格 api 获取电子表格列表,

Oauth1 方式

spreadSheetService = gdata.spreadsheet.service.SpreadsheetsService()
spreadSheetService.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.HMAC_SHA1,self.CONSUMER_KEY,self.CONSUMER_SECRET,two_legged_oauth=True, requestor_id=self.requestor_id)
spreadSheetService.GetSpreadsheetsFeed(query = q)

但是由于此 won't fix issue #594 由于 spreadSheetService 不适用于 OAuth2

如何使用 gdata.spreadsheets.client.SpreadsheetClient 查询电子表格列表?

最佳答案

(假设Python)

我可以使用 gd_client.auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)获取由 OAuth2 流(使用 oauth2client)创建的凭证对象,并将其与 gdata 库一起使用。

完整示例在这里(对于命令行应用程序):

# Do OAuth2 stuff to create credentials object
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run

storage = Storage("creds.dat")
credentials = storage.get()
if credentials is None or credentials.invalid:
  credentials = run(flow_from_clientsecrets("client_secrets.json", scope=["https://spreadsheets.google.com/feeds"]), storage)

# Use it within gdata
import gdata.spreadsheets.client
import gdata.gauth

gd_client = gdata.spreadsheets.client.SpreadsheetsClient()
gd_client.auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
print gd_client.get_spreadsheets()

如果您专门寻找 2-legged,同样的技术也适用,但您需要创建不同类型的凭证对象。请参阅以下有关如何创建它的最新答案:Using Spreadsheet API OAuth2 with Certificate Authentication

关于gdata - 电子表格列表 Gdata OAuth2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20248555/

相关文章:

google-apps-script - 如何从Google Apps脚本中的数据单元中检索超链接?

google-drive-api - 如何集成 Google Drive 和 Spreadsheet API,以处理特定 Google Drive 文件夹中的电子表格?

jquery - youtube搜索结果适用于orderby = viewCount,但不适用于orderby = published

oauth - 无法在oauth2中验证电子邮件地址吗?

iphone - GData 未使用 Apple LLVM 4.1 进行编译

javascript - Heroku Google OAuth 错误

oauth-2.0 - OAuth2 的客户端 JS 库如何维护安全认证?

oauth - 谷歌混合协议(protocol)身份验证问题

r - read.xls-读取长度可变的工作表列表及其名称