估计 API 整合

Estimote API integration

所以我一直在尝试集成 Estimote API 以将信标列表带到我的个人 CMS 中,我遇到了收到 "Unauthorised" 消息的问题,我已经阅读了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

您正在做的是尝试通过获取请求发送 post 字段。

您可以删除此行 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);