Trying out the Surveys API sample Python script, the "List Surveys" command returns only a request_id and not a "resources" object with a list of surveys as expected
Executing the sample script
surveysAPI.py --service_account --service_account_secrets_file certificate.json list
Results of "list" command to_json method:
{
"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": []
}
Response from executing the list command - no "resources" object as advertised.
{
u'requestId': u'5742026000ff0e1cfc8a2e45010001737e3430322d747269616c320001707573682d30352d32302d7230380001013d'
}
I have some 150 surveys in my account. This command works fine in the API explorer and I can use the chain of next page tokens to go through the list.
What am I doing wrong please?
It looks like you're trying to list surveys owned by your account using a service account. In order to do this you''ll need to add the service account as an owner to the resources that your account owns. There is some more information on this process found here: How can I allow a user to get access to survey results using the Google Consumer Surveys API?
Alternatively, you can set up a 3 legged OAuth client secret and use that with the example script. This will prompt you to login as your regular non-service account and use those credentials. See https://developers.google.com/identity/protocols/OAuth2WebServer to set this up.
Then you can use the client with this credential. ./example_client.py list --client_secrets_file
Make sure to configure the credentials to redirect to localhost:8080 if you are using the example script.
来源:https://stackoverflow.com/questions/37378562/surveys-list-api-doesnt-return-resource-dictionary