继上一个问题之后 - Uber API - Price Estimates 需要 HTTPS?- 我已经在我们的网站上设置了 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 的子文件夹中,但我认为这不会引起问题。
关于出了什么问题的任何想法?