【发布时间】:2015-11-18 08:02:40
【问题描述】:
我正在尝试向 Instagram 地理订阅 API 端点发出 POST 请求。
我遇到了和其他人一样的错误:
OPTIONS https://api.instagram.com/v1/subscriptions/
XMLHttpRequest cannot load https://api.instagram.com/v1/subscriptions/.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1337' is therefore not allowed access. The response had HTTP status code 405.
我在前端使用 Node/Express 和 Angular。
这是我在 Angular 中使用 $http 服务提出的请求:
$http.post('https://api.instagram.com/v1/subscriptions/',
{
client_id: 'XXX',
client_secret: 'XXX',
object: 'geography',
aspect: 'media',
lat: 35.657872,
lng: 139.70232,
radius: 1000,
callback_url: 'http://localhost:1337/auth/instagram/callback'
})
.success(function (data, status) {
console.log("success", data);
})
.error(function (data, status) {
console.log("error", data);
});
通过其他 SO 帖子的帮助,我设置了这样的标题:http://repl.it/BDYf
我的应用程序的整体结构取自这个 MEAN 堆栈生成器,如果对这些内容有任何混淆,我链接的 repl.it 所需的文件来自这个 - https://github.com/FullstackAcademy/fsg/tree/master/generated/server
非常感谢一些帮助 - 在使用 $http.jsonp 之前,我遇到了一个 CORS 问题,但正如您所知,您不能将 jsonp 用于 POST 请求,这是 API 所要求的.
谢谢!
【问题讨论】:
标签: javascript node.js express cors instagram-api