javascript - Instagram API获取JavaScript Access-Control-Allow-Origin

标签 javascript instagram-api options preflight

我已尽我所能使此代码正常工作。我正在使用React。我在下面发布了一个端点。我尝试使用提取然后再使用超级代理(也许很重要),但我都无法正常工作。我得到了这两个错误。仅供参考,我有意“ x”出了userId和访问令牌。

OPTIONS https://api.instagram.com/v1/users/xxxxxxxxx/media/recent/?access_token=xxxxxxxx 405 ()



Failed to load https://api.instagram.com/v1/users/xxxxxxx/media/recent/?access_token=xxxxxx: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 405.

我尝试了this postthis post并实现了他们的解决方案,但是一个返回的对象没有我需要的数据,而另一个则不起作用。但是,当我将完整的URL粘贴到浏览器中时,便能够取回JSON对象。请帮忙。

      export const getIGPost = () => dispatch => {
    // fetch('https://api.instagram.com/v1/users/xxxxxxxx/media/recent/?
     access_token=xxxxxxx',{
    //     method:'GET',
    //     dataType:'jsonp',
    //     crossDomain:true
    // })
    request
        .get(`https://api.instagram.com/v1/users/xxxxxxxxx/media/recent/?access_token=xxxxxxxxx`)
        .set('Access-Control-Allow-Origin', 'http://localhost:3000')
        .then(res => {
            if(res.ok) {
                console.log(res.body)
                // dispatch(addIGPost(res.body))
            }
        })
}

最佳答案

解决此问题的简单方法是使用CorsAnywhere

关于javascript - Instagram API获取JavaScript Access-Control-Allow-Origin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47122006/

相关文章:

optimization - gcc的-static选项?

javascript - jQuery:如果未成功删除帮助程序,如何阻止其被删除

javascript - Google Apps 脚本 - 包含外部文件的模板语句不起作用

javascript - asp.net 使用 javascript 打印页面

android - 如何在 Android 中通过 Instagram API 获取推荐的关注者列表

instagram-api - 抱歉,Instagram API : This endpoint has been retired 出现错误

regex - vi:::s 如何只替换一行中的第二次出现?

javascript - RoR - .js 查看更多按钮(顶部)到查看更少按钮(底部)

instagram - 在没有 ACCESS_TOKEN 的情况下调用 Instagram API

visual-c++ -/show在g++中包含等效选项