0

试用 Surveys API 示例 Python 脚本时,“List Surveys”命令仅返回 request_id 而不是“resources”对象,其中包含预期的调查列表

执行示例脚本

调查API.py --service_account --service_account_secrets_file certificate.json 列表

“list”命令 to_json 方法的结果:

{
  "body": null,
  "methodId": "consumersurveys.surveys.list",
  "resumable_uri": null,
  "headers": {
    "accept-encoding": "gzip,deflate",
    "accept": "application/json",
    "user-agent": "google-api-python-client/1.5.1 (gzip)"
  },
  "uri": "https://www.googleapis.com/consumersurveys/v2/surveys?alt=json",
  "resumable": null,
  "body_size": 0,
  "resumable_progress": 0,
  "method": "GET",
  "_in_error_state": false,
  "response_callbacks": []
}

执行列表命令的响应 - 没有广告中的“资源”对象。

{
  u'requestId': u'5742026000ff0e1cfc8a2e45010001737e3430322d747269616c320001707573682d30352d32302d7230380001013d'
}

我的帐户中有大约 150 个调查。此命令在 API 资源管理器中运行良好,我可以使用下一页令牌链来浏览列表。

请问我做错了什么?

4

1 回答 1

2

您似乎正在尝试使用服务帐户列出您的帐户拥有的调查。为此,您需要将服务帐户作为所有者添加到您帐户拥有的资源中。可以在此处找到有关此过程的更多信息: 如何允许用户使用 Google 消费者调查 API 访问调查结果?

或者,您可以设置一个 3 腿 OAuth 客户端密码并将其与示例脚本一起使用。这将提示您以常规非服务帐户身份登录并使用这些凭据。请参阅 https://developers.google.com/identity/protocols/OAuth2WebServer进行设置。

然后,您可以使用具有此凭据的客户端。./example_client.py 列表 --client_secrets_file

如果您使用示例脚本,请确保将凭据配置为重定向到 localhost:8080。

于 2016-05-22T22:17:56.467 回答