【问题标题】:Instagram public API (/?__a=1) works, but only sometimesInstagram 公共 API (/?__a=1) 有效,但仅在某些时候有效
【发布时间】:2021-02-18 15:03:22
【问题描述】:

所以我正在尝试使用公共 API 提取一些 Instagram 图片:

const url = `https://www.instagram.com/${username}/?__a=1`;

fetch(url)
    .then(response => response.json())
    .then(data => {
        prepareImages(data['graphql']['user']['edge_owner_to_timeline_media']['edges'])
    })
    .catch(error => console.log(error));

这在 5 次中有 4 次都可以正常工作。但是,偶尔,我会收到一条错误消息:

CORS 政策已阻止从源“https://test.com”访问“https://www.instagram.com/instagram/?__a=1”获取:否“访问控制允许” -Origin' 标头存在于请求的资源上。如果不透明的响应满足您的需求,请将请求的模式设置为“no-cors”以获取禁用 CORS 的资源。

我已尝试将模式更改为“no-cors”,但这只会导致空响应。你们是否认为他们有时只是阻止请求以防止垃圾邮件?

【问题讨论】:

    标签: javascript node.js fetch instagram


    【解决方案1】:

    您可以尝试使用 graphql,通过使用查询哈希或查询 id 在这篇文章 Instagram ?__a=1 url not working anymore & problems with graphql/query to get data 中获得更多信息

    【讨论】:

      猜你喜欢
      • 2012-02-11
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2018-12-11
      • 2018-02-19
      • 2020-09-14
      • 1970-01-01
      相关资源
      最近更新 更多