如何在没有CORS错误的情况下使用axios对instagram进行api调用 [英] How to make api call to Instagram with axios without CORS error

查看:106
本文介绍了如何在没有CORS错误的情况下使用axios对instagram进行api调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

componentDidMount() {
let token = this.getAccessToken('access_token');

let config = {
  headers: {
    'Access-Control-Allow-Origin': '*',
    'Content-Type': 'application/json',
    Accept: 'application/json'
  }
}

if (token) {
  axios.get('https://api.instagram.com/v1/users/self/?access_token=' + token, config)
    .then(res => {
      console.log(res)
    })
    .catch(err => {
      console.log(err)
    })
}

尝试调用Instagram的API,但我不断收到此错误:

Trying to make an call to Instagram's API but I keep getting this error:

我正在使用React.

I'm using React.

任何帮助都会很棒.

推荐答案

我不认为Instagram支持跨源请求.他们确实支持jsonp.

I don't think Instagram supports cross origin requests. They do support jsonp though.

使用instagram api的Access-Control-Allow-Origin

instagram jquery ajax type =" GET,can'绕开CORS

这篇关于如何在没有CORS错误的情况下使用axios对instagram进行api调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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