创建Instagram API地理订阅的CORS问题
CORS Issue with Creating an Instagram API Geography Subscription
我正在尝试向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所需的in文件。如果你对这些内容有任何困惑- https://github.com/FullstackAcademy/fsg/tree/master/generated/server
我非常感谢一些帮助-我有一个CORS问题之前,我用$http跑来跑去。jsonp,但是正如你所知道的,你不能对POST请求使用jsonp,这是API要求的。
谢谢!
我偶然发现了这个答案,尽管它有意义
[https://stackoverflow.com/a/22850652/1271376] [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;
}]);
相关文章:
- 可以'由于CORS问题,无法访问Heroku上的Flask API
- Axios CORS 问题与 Github oauth 未获取访问令牌
- 从JS到PHP;另一个CORS问题(似乎是)
- CORS问题,同时提交数据到谷歌表单的角度
- 使用fabric.fromUrl时出现CORS问题
- 在不同端口上运行时,rest api应用程序服务器(express)和Angulars js应用程序之间的Cors问题
- 节点中的 CORS 问题.js失败
- 使用 xhr 请求 Google Place API 遇到了 CORS 问题
- 访问 WebGL 的 Soundcloud 波形/插图 (三.js) 应用程序 - CORS 问题
- 旧系统的 CORS 问题 - 没有“访问控制允许源”标头
- 快速 JS 中的 CORS 问题
- 在Azure AD B2C中获取令牌时出现CORS问题(隐含流)
- CORS问题-从骨干JS调用web服务
- IE10和跨域资源共享(CORS)问题与图像/画布
- Azure API管理- CORS问题
- Ajax提交与标准Ajax调用的CORS问题
- 可扩展应用程序的CORS问题
- 表达app.get (& # 39;/* ')和api CORs问题
- 创建Instagram API地理订阅的CORS问题
- 可能的CORS问题.发生了什么事,我该如何解决?