创buildInstagram API地理订阅的CORS问题

我正在尝试向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。

这是我在$ http服务中对Angular的请求:

  $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); }); 

通过其他SOpost的帮助,我设置了如下所示的标题: http : //repl.it/BDYf

我的应用程序的整体结构是从这个平均值堆栈生成器和repl.it我链接的文件中所需的来自这个如果有什么这些混淆 – https://github.com/FullstackAcademy/fsg/tree /主/生成/服务器

我非常感谢一些帮助 – 在使用$ http.jsonp之前,我有一个CORS问题,但是正如你所知道的,你不能使用jsonp作为POST请求,这就是API所要求的。

谢谢!

我遇到了这个答案,虽然它是有道理的

[ https://stackoverflow.com/a/22850652/1271376%5D [1 ]

不能直接从客户端进行POST调用,您必须设置代理服务器,使Instagram API调用POST和DELETE,并且您的客户端应用程序可以调用代理服务器。

您需要启用$httpProvider上的交叉源请求。 例如:

 module.config(['$httpProvider', function ($httpProvider) { // configure the HTTP provider to enable cross-origin requests $httpProvider.defaults.useXDomain = true; }]);