【问题标题】:Google Content API for Shopping - Python OAuth invalid_grantGoogle Content API for Shopping - Python OAuth invalid_grant
【发布时间】:2014-08-26 03:04:10
【问题描述】:

我正在尝试使用 google content api 购物来在我的 google 商家帐户 中添加/更新产品。 看来我在使用 OAuth 时遇到了一些问题。

提前感谢您的帮助!

示例代码

f = file("key.p12", 'rb')
CLIENT_SECRET = f.read()
f.close()
ACCOUNT_ID = 'xxxxxxx'
CLIENT_ID = 'xxxxxxxxx.apps.googleusercontent.com'
SERVICE_ACCOUNT_EMAIL =  'xxxxxxxx@developer.gserviceaccount.com'
SCOPE = 'https://www.googleapis.com/auth/structuredcontent'
USER_AGENT = 'content-api-example'

credentials = SignedJwtAssertionCredentials(
    SERVICE_ACCOUNT_EMAIL,
    CLIENT_SECRET,
    scope=SCOPE)

http = httplib2.Http()

http = credentials.authorize(http)

auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)

entry = gdata.contentforshopping.data.ProductEntry()
...
shopping_client.InsertProduct(entry)

输出

auth2client.client.AccessTokenRefreshError: invalid_grant

【问题讨论】:

    标签: python oauth google-api gdata


    【解决方案1】:

    您似乎正在使用服务帐户来访问 API。确保您登录到您尝试访问的相应 Google Merchant Center 帐户,并将从 Google Developer Console 生成的服务帐户电子邮件(在您的代码中,这是 SERVICE_ACCOUNT_EMAIL 中的值)添加到“设置 > 用户”部分,然后根据您请求的范围授予此电子邮件地址“标准”或“管理”访问权限。

    这是一个经常被遗漏的步骤,并且在 Google 的文档中没有特别指出。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      相关资源
      最近更新 更多