实体主体应该是正确嵌套的资源属性名称/值对


Entity body should be a correctly nested resource attribute name/value pair

我是一个使用PHP cURL的初学者,正在尝试使用Box.com API 2.0,它使用oAuth。我正在尝试返回有关用户的基本信息。这是我的代码:

$box_1 = curl_init("https://api.box.com/2.0/users/me");
curl_setopt($box_1, CURLOPT_HTTPHEADER, "Authorization: Bearer token_was_here");
curl_setopt($box_1, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($box_1, CURLOPT_POSTFIELDS, "fields=id,name,login");
$box_curl1 = curl_exec($box_1);
curl_close($box_1);

当我运行此程序时,我会得到以下错误:{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value 'fields=id,name,login'. Entity body should be a correctly nested resource attribute name'/value pair"}]},"help_url":"http:'/'/developers.box.com'/docs'/#errors","message":"Bad Request","request_id":"request_id_was_here"}

当我删除第4行时,我根本没有得到任何响应。

fields=id,name,login应该在查询字符串中,而不是请求正文中。

好吧,我想通了!

我的"访问令牌"已过期,由于我没有选择输出标头,我从未发现这一点!

我还稍微修改了一下我的代码:

$token = "token here";
$box_1 = curl_init();
curl_setopt($box_1, CURLOPT_URL, "https://api.box.com/2.0/users/me?fields=id");
curl_setopt($box_1, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$token));
curl_setopt($box_1, CURLOPT_HTTPGET, TRUE);
curl_setopt($box_1, CURLOPT_RETURNTRANSFER, true);
$box_curl1 = curl_exec($box_1);
curl_close($box_1);