【发布时间】:2015-05-30 23:07:46
【问题描述】:
关于上一个问题 - Uber API - HTTPS needed for Price Estimates? - 我已经在我们的网站上设置了 https。
我在 Uber Developer 上的应用设置了重定向 URL 和源 URL 作为 https 域。
按照此页面上的代码 - https://developer.uber.com/v1/api-reference/#request-response - 我已尝试测试此处给出的代码:-
var xhr = new XMLHttpRequest();
xhr.setRequestHeader("Authorization", "Token YOUR_SERVER_TOKEN");
xhr.open('GET', 'https://api.uber.com/v1/products?latitude=37.7759792&longitude=-122.41823');
不幸的是,我收到错误“Uncaught InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.”。
然后我切换了 .setRequestHeader 和 .open 行,我收到以下错误:-
“XMLHttpRequest 无法加载 https://api.uber.com/v1/estimates/price?start_latitude=53.4521477&start_longitude=-2.2750512&end_latitude=53.4522973&end_longitude=-2.275001。请求的资源上不存在 'Access-Control-Allow-Origin' 标头。因此不允许访问源 'https://milliondollarwiki.co.uk'。”
这是有问题的最终代码:-
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.uber.com/v1/estimates/price?start_latitude=' + position.coords.latitude + '&start_longitude=' + position.coords.longitude + '&end_latitude=53.4522973&end_longitude=-2.275001');
xhr.setRequestHeader("Authorization", "Token bTVn8k_wF3JpmHlZ0GhdbMWaLgbLMSaYof8rs-S_");
xhr.send();
在 Uber API 中交互的 URL 位于 Redirect & Origin URLs 的子文件夹中,但我认为这不会导致问题。
知道出了什么问题吗?
【问题讨论】:
标签: uber-api