php - 使用 Instagram 在服务器中获取数据时出现问题?__a=1 url
问题描述
我正在使用此代码从帐户中获取最后 8-10 个帖子:
$feed_instagram = file_get_contents('https://www.instagram.com/USERNAME/?__a=1');
$feed_instagram = json_decode($feed_instagram, true);
它在我的开发环境(本地)中就像一个魅力。
当我尝试在我的暂存开发 (AWS) 中做同样的事情时,它只会返回一个带有 Instagram 徽标的 HTML。
尝试了我在另一篇文章中看到的另一种方法:
$url = "https://www.instagram.com/USERNAME";
$html = file_get_contents($url);
$arr = explode('window._sharedData = ',$html);
$arr = explode(';</script>',$arr[1]);
$feed_instagram = json_decode($arr[0] , true);
并且在本地也可以工作,但是在 AWS 环境中,它看起来需要登录或其他东西:
[entry_data] => Array
(
[LoginAndSignupPage] => Array
(
[0] => Array
(
[captcha] => Array
(
[enabled] =>
[key] =>
)
[gdpr_required] => 1
[tos_version] => eu
[username_hint] =>
)
)
)
在本地,在“entry_data”中,我得到一个“ProfilePage”对象,其中包含我需要的所有信息。
任何线索为什么会这样?谢谢。
解决方案
解决这个两个月前的问题,Instagram / Facebook 似乎阻止了某些服务 IPS(经过测试的 AWS 和 Digital Ocean)。由于这个项目只需要运行两个月,我最终使用了一个带有 cron 任务的 Raspberry Pi。
推荐阅读
- git - 引入 git switch 后 git checkout 还能做什么?
- docker - gitlab-runner 执行作业时如何避免与当前容器的端口冲突
- java - Minecraft Spigot 插件 - StringLists
- matlab - 向量化具有多个变量的函数
- c++ - 从命名空间内的类调用函数?
- javascript - transition().each() 在 D3 v3 之后发生变化
- java - Java HtmlUnit - 获取 Twitter 结果
- python - 指定用于多重继承的父类
- javascript - CR和CF的javascript textarea maxlength问题
- vb.net - 为什么我的 if 语句只返回第二个结果?