Search code examples
google-sheetsinstagram-api

SyntaxError: Unexpected token < in JSON at position 0 (line 64, file "Instagram Automation") on a previously working code


I have been using this script someone wrote for my google spreadsheet to gather data, and it has been working really well for 10 days, then it suddenly gave me the error:

SyntaxError: Unexpected token < in JSON at position 0 (line 64, file "Instagram Automation")

I altered the code slightly but it gave me instead the error:

TypeError: Cannot read property 'user' of undefined (line 30, file "Instagram Automation")

The bits of code here are:

    function fetch(url) {
  var ignoreError = {
    "muteHttpExceptions": true
  };
  var source = UrlFetchApp.fetch(url, ignoreError).getContentText();////
  ///var data = JSON.parse(source);
  return source;
}

(the /// is what I altered, and returned the source instead)

and

    function getFollowers() {
  return parseInt(fetch(instagram_base_url + followers)['data']['user']['edge_followed_by']['count']);
}

I really hope someone can help! :)

NOTE: I have re-copied all the code like I did the first time incase I accidentally did something that broke it but still got the same errors.

Original github How I came across the code


Solution

  • This person has solved the issue by using a cookie variable inside the script.

    https://gist.github.com/JulienDev/df5a3b66e899c224fa1b2dc90acfa2ae#gistcomment-3531268

    Follow his instructions and I can confirm it does work.