0

I have a site that needs to load some images from Instagram. I'm using Fetch to make the request to Instagram's API. The request is successful but I get this error when processing the request, error SyntaxError: Unexpected end of input.

The request comes back as 200 and with valid JSON. It seems like once the Fetch response completes the response is empty thus resulting in the SyntaxError.

http://jsbin.com/kohito/edit?html,js,console

I removed my access token from the example.

Michael Turnwall
  • 649
  • 7
  • 21

1 Answers1

0

You'll need to go with jsonp to consume the Instagram API using the Client-Side (Implicit) Authentication method. You can bring in fetch-jsonp to make a "fetch-like" request.

  <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch-jsonp/1.1.0/fetch-jsonp.min.js"></script>
  <script>
  fetchJsonp('https://api.instagram.com/v1/users/self/media/recent/?' + window.location.hash.split('#')[1], {
    method: 'GET',
  }).then(response => {
    response.json().then((json) => {
      console.log(json);
    });
  });
  </script>
kevincolten
  • 139
  • 1
  • 9