使用哈希标签获取Instagram图片

时间:2019-01-15 17:08:54

标签: php instagram-api

我想在我的网站上使用井号显示Instagram图片。我想使用哈希标签显示最新照片

如何修复下面的无效代码?

$access_token = "my access token";
$photo_count = 2;
$hashtag ="hashtag";
$json_link = "https://api.instagram.com/v1/users/self/media/recent/?";
$json_link .="access_token={$access_token}&count={$photo_count}&tags={$hashtag}";
$json = file_get_contents($json_link);
$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
//echo "<pre>";
//print_r($obj);
//echo "</pre>";
$i==0;
foreach ($obj['data'] as $post){
    $i++;

    $pic_tags= $post['text'];
    $pic_text = $post['caption']['text'];
    $pic_link = $post['link'];
    $pic_like_count = $post['likes']['count'];
    $pic_comment_count=$post['comments']['count'];
    $pic_src=str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
    $pic_created_time=date("F j, Y", $post['caption']['created_time']);
    $pic_created_time=date("F j, Y", strtotime($pic_created_time . " +1 days"));


    echo "<div class='col-md-6 item_box'>";
        echo "<a href='{$pic_link}' target='_blank'>";
          echo "<img class='img-responsive photo-thumb' src='{$pic_src}' alt='{$pic_text}'>";
        echo "</a>";
    echo "<p>";
    echo "<p>";
        echo "<div style='color:#888;'>";
           // echo "<a href='{$pic_link}' target='_blank'>{$pic_created_time}</a>";
        echo "</div>";
    echo "</p>";
   //echo "<p>{$i}</p>";
   //echo "<p>{count($i)}</p>";
    echo "</p>";
    echo "</div>";

}

0 个答案:

没有答案