如何在没有 CORS 错误的情况下使用 axios 对 Instagram 进行 api 调用 [英] How to make api call to Instagram with axios without CORS error
本文介绍了如何在没有 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.
Access-Control-Allow-Origin 与 instagram api
instagram jquery ajax type="GET,可以'绕过CORS
这篇关于如何在没有 CORS 错误的情况下使用 axios 对 Instagram 进行 api 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文