首页 > 解决方案 > 使用 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”对象,其中包含我需要的所有信息。

任何线索为什么会这样?谢谢。

标签: phpinstagraminstagram-api

解决方案


解决这个两个月前的问题,Instagram / Facebook 似乎阻止了某些服务 IPS(经过测试的 AWS 和 Digital Ocean)。由于这个项目只需要运行两个月,我最终使用了一个带有 cron 任务的 Raspberry Pi。


推荐阅读