[英]“No 'Access-Control-Allow-Origin' header is present on the requested resource” error when sending request to Jawbone UP API
I've built a custom database that I would like to populate with some of my UP3 data. 我已经构建了一个自定义数据库,我想填充一些我的UP3数据。 I've successfully authenticated and received the JSON response with my Bearer token.
我已成功通过Bearer令牌进行身份验证并收到JSON响应。 From here, I'm sort of lost.
从这里开始,我有点迷茫。
From the documentations, I need to send a GET request to 从文档中,我需要发送一个GET请求
https://jawbone.com/nudge/api/v.1.1/users/@me
Each time I do, I get: 每次我这样做,我得到:
No 'Access-Control-Allow-Origin' header is present on the requested resource
请求的资源上不存在“Access-Control-Allow-Origin”标头
I've added: 我已经添加:
header('Access-Control-Allow-Origin: http://example.com');
(replacing example.com with my domain) (用我的域名替换example.com)
to the page that is sending the GET request. 到发送GET请求的页面。 Any thoughts?
有什么想法吗?
The Jawbone endpoints all have the CORS header set to Jawbone端点都设置了CORS标头
Access-Control-Allow-Origin: *
However, this still will not allow cross-site requests from localhost (thanks @TirthrajBarot for the explanation in the comments), so you should disable this check in Chrome with something like the Access-Control-Allow-Origin extension . 但是,这仍然不允许来自localhost的跨站点请求(感谢@TirthrajBarot在评论中的解释),因此您应该在Chrome中禁用此类检查,例如Access-Control-Allow-Origin扩展名 。
After authenticating the user and permissions, I redirect to another page to validate the authentication code and get the access token. 在对用户和权限进行身份验证后,我将重定向到另一个页面以验证身份验证代码并获取访问令牌。 From there, I go to another page to send the GET request for the data.
从那里,我转到另一页面发送数据的GET请求。 Here is the code that is working:
这是正在运行的代码:
$url = "https://jawbone.com/nudge/api/v.1.1/users/@me/sleeps?" . $sleepDate;
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept: application/json\r\n" .
"Authorization: Bearer " . $accessToken . "\r\n" .
"Host: {my website}"
)
);
$context = stream_context_create($options);
$sleepData = @file_get_contents($url, false, $context);
The data is returned, decoded, and processed. 返回,解码和处理数据。 The result is pushed into a text box in a form for the user to edit if desired.
结果被推入表单中的文本框中,供用户根据需要进行编辑。 There is also a button to enter the data into the database (along with a bunch of hidden form fields that enter other relevant details)
还有一个按钮可以将数据输入数据库(以及输入其他相关详细信息的一堆隐藏表单字段)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.