2

Instagram's "API" lets me GET json from this endpoint: https://www.instagram.com/natgeo/?__a=1

TL;DR

How can I go about making AJAX requests with credentials so that I can load authenticated JSON content from Instagram's "API"? Is a proxy my best bet?

At the end of the day, I just want to be able to GET with ajax (with credentials, thus violating Same Origin) just like how I can if I manually reloaded https://www.instagram.com/natgeo/?__a=1. It would be great if I could do it server side because all the questions I've read on stackoverflow seem to like the frontend side of things.

The JSON response is large but contains the following (for logged in users who follow natgeo):

{
  "user": {
  "biography": "...",
   ...
  "followed_by_viewer": true,
}

The "followed_by_viewer" property clearly uses my cookies and credentials because if I am signed in , the result is: "followed_by_viewer": true.

However, if I make an ajax GET request, the result is "followed_by_viewer": false

I want to get authenticated data asynchronously with axios or jQuery's ajax. I looked up the problems and learned a bit about CORS and headers that I could send. I tried withCredentials and that didn't work either. I tried crossOrigin: true. There was always some error. I even downloaded an extension for chrome that changes the request headers. Alas, I kept getting console errors.

'Access-Control-Allow-Credentials' header in the response is '' which must 
be 'true' when the request's credentials mode is 'include'.

Then I read about how I could use a proxy but I was confused about how I would go about implementing it. Would I pass credentials to the proxy and then the proxy makes the request?

I have a server with create-react-app and axios from localhost:3000 so the same origin policy errors make sense but I don't want a solution with JSONP because it seems outdated and frustrating. Here are some stack overflow questions that I've read:

0 Answers0