Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Python访问Google购物API_Python_Google Content Api - Fatal编程技术网

通过Python访问Google购物API

通过Python访问Google购物API,python,google-content-api,Python,Google Content Api,我对谷歌API很陌生,我有点迷路了:) 首先,我和他一起玩,所有的要求都很好 然后,我开始编写一个小的Python脚本来授权并通过服务帐户调用API 看起来是这样的: from apiclient.discovery import build from oauth2client.service_account import ServiceAccountCredentials import httplib2 import json import os credentials = Servic

我对谷歌API很陌生,我有点迷路了:)

首先,我和他一起玩,所有的要求都很好

然后,我开始编写一个小的Python脚本来授权并通过服务帐户调用API

看起来是这样的:

from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

import httplib2
import json
import os


credentials = ServiceAccountCredentials.from_json_keyfile_name(
    filename='/Users/Shopping Dashboard.json',
    scopes='https://www.googleapis.com/auth/content')

http = credentials.authorize(httplib2.Http())

service = build('content', 'v2', http=http)
print service.accounts().authinfo().execute()

request = service.accounts().list(merchantId='xxx', maxResults=50)
result = request.execute()
print result
然而,虽然我认为这是一种好,我仍然得到这个错误

googleapiclient.errors.HttpError: <HttpError 401 when requesting https://www.googleapis.com/content/v2/xxxxx/accounts?alt=json&maxResults=50 returned "User cannot access account xxxxx">
googleapiclient.errors.HttpError:
我想我错过的是在调用url之前创建我的令牌(?)?但这是如何产生的呢?我知道有1000个例子,我使用了一些已经在github中的脚本,它们可以工作,但是它们已经太复杂了,我无法理解。我在这里错过的是通过一些简单的例子来理解这个过程是如何工作的,并且能够复制逻辑


非常感谢

这可能是象征性的东西。在使用这种类型的API时,始终需要一个令牌。但是,请检查一下如何使用urllib2完成此操作。

我也遇到了同样的问题。事实证明,“Shopping Dashboard.json”文件必须来自merchant center本身,而不是google开发者控制台

  • 确保你有管理员权限
  • 在商业中心去。。。下拉菜单>内容API
  • 单击“身份验证”选项卡并生成API密钥。只有当您具有管理员权限时,才能看到此选项卡
  • 保存content-api-key.json代替/Users/Shopping Dashboard.json

我仍然不明白,我不确定服务帐户中是否确实存在这种情况。例如,在这段代码中没有标记:我相信来自github的代码示例非常清晰,注释也非常有用。但是您是否尝试过在不向list方法添加参数的情况下运行代码?