1

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

$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 行时,我根本没有得到任何回应。

4

2 回答 2

1

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

于 2013-06-28T18:48:40.597 回答
0

嗯,我想通了!

我的“访问令牌”已经过期,由于我没有选择输出标题,所以我从来没有发现这个!

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

$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);
于 2013-06-28T19:27:20.297 回答