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,但我一直收到此错误:
我正在使用React。
任何帮助都会很棒。
答案 0 :(得分:2)
我不认为Instagram支持跨源请求。他们确实支持jsonp。
答案 1 :(得分:0)
您可以使用中间人在服务器端发出请求。当我搜索没有cors npm'时,有几个可供选择,但这里有一个例子:implement Dijkstra's algorithm with a binary heap