当我将Angularjs与instagram API一起使用时,CORS错误 [英] CORS error, when i use instagram API with angularjs

查看:77
本文介绍了当我将Angularjs与instagram API一起使用时,CORS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务很简单-从instagram帐户获取用户的数据。我使用标准的instagram api和angularjs。

I have simple task - get users' data from instagram account. I use standard instagram api and angularjs.

这是控制器的请求方法:

Here is controllers' request method:

 $http({
  method: 'GET',
  url: 'https://api.instagram.com/v1/users/6976008122/media/recent/?access_token=1030475459.50cd673.aa04db13898d4fsd9ff8fe5095b32f34&scope=public_content&count=4'
    }).then(function(res) {
      console.log(res);
    }, function(err) {
      console.log(err);
    });

但我总是收到此错误消息:

But I always get this error message:

对预检请求的响应未通过访问控制检查:在请求的
资源上没有
'Access-Control-Allow-Origin'标头。因此,不允许访问来源 http://project.loc
响应的HTTP状态代码为405。

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://project.loc' is therefore not allowed access. The response had HTTP status code 405.

Google搜索的前几页没有帮助,请帮助我理解并解决此问题。

The first few pages of Google search has not helped, please help me understand and solve this problem.

推荐答案

使用jsonp,这里有一个很好的示例: JSONP Instagram

Use jsonp, there's a good example located here: JSONP Instagram

这里是链接另一个Stack Overflow问题,该问题解释了如何使用角度 Angular Jsonp

Here's a link to another Stack Overflow question that explains how to do jsponp with angular Angular Jsonp

这篇关于当我将Angularjs与instagram API一起使用时,CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆