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

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

我一直在使用某人为我的 google 电子表格编写的这个脚本来收集数据,它已经运行了 10 天,效果非常好,然后它突然给我错误:

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

我稍微修改了代码,但它给了我错误:

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

这里的代码位是:

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

(/// 是我更改的内容,而是返回了源代码)

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

真心希望有人能帮忙! :)

注意:我已经像第一次一样重新复制了所有代码,以防我不小心做了一些破坏它的事情,但仍然有同样的错误。

Original github How I came across the code

我正在使用相同的脚本,并且在日志(片段)中收到以下响应:

[20-11-18 12:28:58:326 AEDT] Logging output too large. Truncating output. <!DOCTYPE html>
<html lang="en" class="no-js not-logged-in ">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <title>
                  Page Not Found &bull; Instagram
                </title>

        
        <meta name="robots" content="noimageindex, noarchive">
        <meta name="apple-mobile-web-app-status-bar-style" content="default">
        <meta name="mobile-web-app-capable" content="yes">
        <meta name="theme-color" content="#ffffff">
        <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover">
        <link rel="manifest" href="/data/manifest.json">

我已经在浏览器选项卡中测试了 fetch URL 结构,我得到了一个 JSON 所以我很困惑为什么响应是找不到页面。

我能看到的唯一其他提示是 class 未登录

这是因为,在最后一天,Instagram 更新了使用 cookie 的政策。如果您以注册用户身份登录,您可能会得到具有所需 JSON.

的正确结果

但是如果您的 IP 被泄露,例如在隐身选项卡中,您将被重定向到登录页面。这对应于您附加的 HTML 代码。

在开发者工具中,您会看到 302 重定向到登录页面。如果你能突破到一个标签搜索页面,比如你会发现滚动的时候没有加载新的数据。

我想很快会有更多关于这个问题的讨论。

此人已通过在脚本中使用 cookie 变量解决了问题。

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

按照他的指示进行操作,我可以确认它确实有效。