1

I have done everything I can imagine to get this code to work. I am using React. I have an endpoint which I have posted below. I tried using fetch and then superagent (maybe that's important), and I could get neither to work. I get these two errors. FYI, I have intentionally "x'd" out the userId and access token.

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

and

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.

I tried this post and this postand implemented their solution but one the object that was returned did not have the data that I needed and the other just didn't work. However, I am able to get the JSON object back when I paste the complete URL in my browser. Please help.

      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))
            }
        })
}
bad_coder
  • 11,289
  • 20
  • 44
  • 72
str8up7od
  • 338
  • 3
  • 15

0 Answers0