首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Chrome发布API和OAuth2服务帐户

使用Chrome发布API和OAuth2服务帐户
EN

Stack Overflow用户
提问于 2015-04-10 17:35:38
回答 2查看 1.1K关注 0票数 1

我尝试使用Chrome发布API以编程方式更新一个铬应用程序。

我需要使用服务器到服务器身份验证方法,并为此在控制台上为我的项目创建了一个控制台服务帐户。并将凭据下载为key.p12。

然后我尝试使用用于Python的Google客户端。即使API不支持,也应该可以使用它的一部分。

我用Python创建了一个小脚本,试图获取项目的列表:

代码语言:javascript
复制
"""Creates a connection to Google Chrome Webstore Publisher API."""

from apiclient.discovery import build
import httplib2
from oauth2client import client

import os

SERVICE_ACCOUNT_EMAIL = (
    '_SOME_126736126931_RUBISH_@developer.gserviceaccount.com')

def getservice():
    # get relative path to p12 key
  dir = os.path.dirname(__file__)
  filename = os.path.join(dir, 'key.p12')

  # Load the key in PKCS 12 format that you downloaded from the Google APIs
  # Console when you created your Service account.
  f = file(filename, 'rb')
  key = f.read()
  f.close()

  # Create an httplib2.Http object to handle our HTTP requests and authorize it
  # with the Credentials. Note that the first parameter, service_account_name,
  # is the Email address created for the Service account. It must be the email
  # address associated with the key that was created.
  credentials = client.SignedJwtAssertionCredentials(
      SERVICE_ACCOUNT_EMAIL,
      key,
      scope='https://www.googleapis.com/auth/chromewebstore.readonly')
  http = httplib2.Http()
  http = credentials.authorize(http)

  response = http.request('https://www.googleapis.com/chromewebstore/v1.1/items/[___my_chrome_webstore_app_id___]')

  print response

尽管authentication in https://www.googleapis.com/auth/chromewebstore.readonly成功的,但是响应会导致403错误。

我的问题:

  1. 由于服务帐户没有访问我的google网站项目,会发生403吗?
  2. 是否可以不使用我的个人帐户来验证和使用Chrome,该帐户发布到web商店(但连接的服务帐户)?
  3. 如何在没有用户通过authToken进行身份验证的情况下检索用于Chrome的有效flow
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-04-14 10:19:41

实际上我的剧本有两个问题。

  1. 用户 ( a)要使服务帐户代表发布到chrome网站的用户,您需要在创建凭据时添加一个子参数: 凭据= client.SignedJwtAssertionCredentials( SERVICE_ACCOUNT_EMAIL,key,scope='https://www.googleapis.com/auth/chromewebstore.readonly',scope=)

b)如果用户是Google域的一部分,Chrome发布API需要在Google Apps Dashboard > Security > Extended Settings > Manage API access上被授予访问域范围用户的权限

  1. 获取项的API调用有一个必需的查询参数projection,其值为draftpublished。它在文档中是可选的,但实际上是必需的。

通过这两个更改,API可以与http对象一起使用。感谢你们所有人,他们帮助我找到了解决方案,感谢Google支持,他们指出了所需的参数。

票数 2
EN

Stack Overflow用户

发布于 2015-04-10 18:19:02

  1. 由于服务帐户没有访问我的google网站项目,会发生403吗?

可能吧。一个服务帐户是,而不是你自己的帐户。

  1. 是否可以不使用我的个人帐户来验证和使用Chrome,该帐户发布到web商店(但连接的服务帐户)?

不知道。对不起,不熟悉Chrome。您可以使用Oauth游乐场来测试这些可能性,而不必编写任何代码。

  1. 如何在没有用户通过流进行身份验证的情况下检索用于Chrome的有效authToken。

通过使用“脱机访问”授权一次,这将返回一个刷新令牌。您可以在任何时候使用它,即使没有登录,也可以请求访问令牌。顺便说一句,根本就没有“创作托肯”这样的东西。有授权代码和访问令牌。在您的例子中,它是您感兴趣的访问令牌。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29567470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档