得到别人的公共Instagram饲料

时间:2018-01-28 11:56:10

标签: wordpress instagram feed

很多小部件和片段用于显示您自己的Feed,但似乎找不到任何用于显示其他人的公共Feed。

需要这个我正在进行的项目。

http://instafeedjs.com声称您可以根据标签获取图片,这些标签几乎已经足够,但它不起作用,所以我认为Instagram API已经过改进。

为什么Instagram限制访问公开的内容?

1 个答案:

答案 0 :(得分:0)

Instagram看起来确实限制了他们的API,但是当使用以下网址发出请求时,您仍然可以获得用户信息:

https://www.instagram.com/ {名} /?__一个= 1

例如:此网址将获取有关用户名为“锁定”的用户的所有信息 https://www.instagram.com/therock/?__a=1

这是我的解决方案,特别是这适用于wordpress:

            <?php 

            // The instagram user eg: elonmusk
            $instagramId = get_field('instagram_id');
            if($instagramId) {
                $request = wp_remote_get( 'https://www.instagram.com/' . $instagramId . '/?__a=1' );
                if( is_wp_error( $request ) ) { return false; // Something }
                $body = wp_remote_retrieve_body( $request );
                $data = json_decode( $body, true );

                // Get the actual user ID eg: 3602415960
                $userID = $data["user"]["id"];

              }?>

然后最后使用instafeedjs中的userID来显示提要。

            <div id="instafeed">
            </div>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/instafeed.js/1.4.1/instafeed.min.js"></script>
            <script type="text/javascript">
                var php_var = "<?php echo $userID; ?>";
                var userFeed = new Instafeed({
                    get: 'user',
                    userId: php_var,
                    clientId: '*******Enter yours******',
                    accessToken: '4622774.7cbaeb5.ec8c5041b92b44ada03e4a4a9153bc54',
                    template: '<a href="{{link}}" target="_blank" id="{{id}}"><img src="{{image}}" style="width:25%;"/></a>',
                    sortBy: 'most-recent',
                    limit: 24,
                    links: false
                });
                userFeed.run();
            </script>

http://instafeedjs.com

https://pippinsplugins.com/using-wp_remote_get-to-parse-json-from-remote-apis/

我真的希望这有助于其他人。