所以我一直在尝试集成 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
最佳答案
您正在做的是尝试通过 get 请求发送 post 字段。
你可以删除这一行 curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
在文档中https://cloud.estimote.com/docs/#api-General-Authorization它说您需要将您的 appid 作为用户名和 token 作为密码发送。在 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);
关于php - 估计 API 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36099060/