4

所以我一直在尝试集成 Estimote API 以将信标列表带到我的个人 CMS,我遇到的问题是我通过 Api 文档和通用文档阅读了“未经授权”消息 - 授权是我可以,因为我带来了我的云帐户中的信标,所以在 curl 请求中有一个示例,我可以通过执行以下操作获取信标列表:

curl -u app_0a1b2c3d4e:0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d \
     -H 'Accept: application/json' \
     https://cloud.estimote.com/v1/beacons

问题是我一直在尝试这样做,它说通常我应该使用 App ID 和 App Token 来授权我的请求

header('Content-Type: application/json');

$app_id = "appid";
$token = "token";
$ch = curl_init('https://cloud.estimote.com/v1/beacons?appid='.$appId.'&apptoken='.$token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));

$result = curl_exec($ch);

print_r($result);
curl_close($ch);

关于我做错了什么的任何想法? https://cloud.estimote.com/docs/#api-Beacons-GetBeacons

4

1 回答 1

3

您正在做的是尝试发送带有获取请求的帖子字段。

您可以删除此行curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

在文档https://cloud.estimote.com/docs/#api-General-Authorization中,它说您需要将您的 appid 作为用户名和令牌作为密码发送。在 curl 你有那个选项。

尝试这个

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://cloud.estimote.com/v1/beacons');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$appid:$token");
$output = curl_exec($ch);
curl_close($ch);
于 2016-03-19T07:34:06.927 回答