Expected object or value

允我心安 提交于 2019-12-11 02:24:36

问题


I have setup a developer account and created a access token as described in the docs using "custom application" and providing key, id and secret in the console.

Requests made via the console such as get_survey_list work fine.

However if I try any other http client like curl I get this:

{"status":3,"errmsg":"Expected object or value"}

The curl code is:

curl -H 'Authorization:bearer xxx' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxx --data-binary ''

I have tried other methods (httpclient, poster, in my appliction) I always get this result. My request looks absolutely identical to the request data that is shown in the console output.

The only request that works is user/get_user_details.

Can anybody help? Thanks Gordon


回答1:


You have to request certain data fields with the --data-binary flag. For example, if I want:

"title","analysis_url","date_created","date_modified"

my curl statement looks like this:

curl -H 'Authorization:bearer xxx' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxx --data-binary '{"fields":["title","analysis_url","date_created","date_modified"]}'

(please replace XXX with your authenticate parameters)

Read more details here - the page also includes a full example of the curl statement:

curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=your_api_key --data-binary '{"fields":["title","analysis_url","date_created","date_modified"], "start_date":"2013-02-02 00:00:00", "end_date":"2013-04-12 22:43:01", "order_asc":false, "title":"test3"}'



回答2:


get_survey_details can be called with no parameters, but it still requires a valid JSON object to be POSTed. As Miles commented, a simple empty JSON object will suffice: {}

The error message you got, "Expected object or value", indicates that no JSON object could be decoded from the POST data.



来源:https://stackoverflow.com/questions/23909021/expected-object-or-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!