How to get a user's Instagram feed

后端 未结 7 846
北海茫月
北海茫月 2020-12-04 23:10

I\'d like to get a user\'s Instagram feed using PHP. I\'ve signed up for an Instagram Developer Account and tried pulling in a user\'s info and photos, but the response isn

相关标签:
7条回答
  • 2020-12-04 23:48

    try this one a crawler type in raw form.

    function feed_instagram($url = "https://www.instagram.com/titaniumheart_")
    {  
        //$url ie https://www.instagram.com/titaniumheart_
    
        $dom = new DOMDocument();
        @$dom->loadHTMLFile($url);
        $f=$dom->saveHTML();  //load the url (crawl)
    
        $key="";    
        $swquote=0;     
        echo "<div>";
    
        for ($x=0;$x<strlen($f);$x++)
        {
           $c=substr($f,$x,1);
           //echo $c."-";
            if ($c==chr(34)) 
            {
                if($swquote==0)
                {
                    $swquote=1; //to start get chars
                } else
                {
                    $swquote=0;
                    //echo $key;
                    if($key=="code")
                    {
                        //get the number of comments
                        $m=substr($f,$x+4,100);
                        $code= substr($m,0,strpos($m,chr(34)));
                        echo "code is ".$code;
                        echo "<br>";
                    }               
                    if($key=="comments")
                    {
                        //get the number of comments
                        $m=substr($f,$x+12,20);
                        $comments= substr($m,0,strpos($m,"}"));
                        echo "number of comments is ".$comments;
                        echo "<br>";
                    }
                    if($key=="caption")
                    {
                        //get the number of comments
                        $m=substr($f,$x+4,200);
                        $caption= substr($m,0,strpos($m,chr(34)));
                        echo "caption is ".$caption;
                        echo "<br>";
                    }
                    if($key=="likes")
                    {
                        //get the number of comments
                        $m=substr($f,$x+12,20);
                        $likes= substr($m,0,strpos($m,"}"));
                        echo "number of likes is ".$likes;
                        echo "<br>";
                    }
                    if($key=="thumbnail_src")
                    {
                        //get the number of comments
                        $m=substr($f,$x+4,200);
                        $src= substr($m,0,strpos($m,"?"));
                        echo "<br>image source is ".$src;
                        echo "<br>";                                    
                        echo "<a href=\"https://www.instagram.com/p/".$code."/\">";
                        echo "<img src=\"".$src."\">";
                        echo "</a><br>";                    
                    }                               
                   $key="";
            }
    
        }else
        {
            if($swquote==1)
            {
                $key.=$c;
            }
        }           
    }
    echo "</div>";
    }
    

    usage: https://www.instagram.com/titaniumheart_");?>

    take note: you must enabled extension "php_openssl" on php.ini.

    0 讨论(0)
提交回复
热议问题