将“加载更多”按钮添加到Instagram Feed

时间:2015-03-19 22:26:24

标签: php json instagram instagram-api

我在网站上有一个有效的Instagram Feed。另一位开发人员写了它,我需要添加一个Load More按钮,以便我们可以看到超过20张照片的Instagram加载。我不是一个程序员,我读了Instagram API,但它让我更加困惑。我已经尝试了几种我在堆栈溢出时发现的解决方案,但不断得到解析错误。我的工作代码如下,如果有人可以告诉我如何添加“加载更多”按钮甚至分页我会很感激。

    <?php
       function fetchData($url){
         $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        $result = curl_exec($ch);
        curl_close($ch); 
        return $result;
      }

  $client_id = "XXXXClientIDXXXX";
  $tag = $modx->getObject('modResource',22);
 $tagValue = $tag->getTVValue('photo-feed-hash');

 $url = 'https://api.instagram.com/v1/tags/'.$tagValue.'/media/recent?  client_id='.$client_id;
$result = fetchData($url);


$result = json_decode($result);
foreach ($result->data as $post) {
    echo '
    <div class="photo-tile '.$post->user->username.'">
        <a class="lightbox" rel="gallery1" title="'.$post->user->username.' - '.$post->caption->text.'" href="'.$post->images->standard_resolution->url.'">
            <img src="'.$post->images->low_resolution->url.'" />
            <span>'.$post->user->username.'</span>
        </a>
    </div>';
   if (isset($_POST['more'])) {
     $result = fetchData("https://api.instagram.com/v1/tags/apple/media/recent/?access_token=964985675.5b9e1e6.aede14d1d33e4cc8b11662af423b9762&count=15&max_id=1387332905573");
$result = json_decode($result);
foreach ($result->data as $post) {
    echo '<div class="instagram-unit"><p class="instagram-desc">'.htmlentities($post->caption->text).'</p>
    <a class="instagram-link fancybox-media" rel="gallery" title="'.htmlentities($post->caption->text).'" href="'.$post->link.'">
    <img class="instagram-img" src="'.$post->images->thumbnail->url.'"/></a>
    </div>';
}
}
 ?>
  <form method="post" action="">
  <input class="submit" type="submit" name="more" />

1 个答案:

答案 0 :(得分:0)

你有4个开口花括号({),但只有3个花括号(})。这就是你得到解析错误的原因。

更改

if (isset($_POST['more'])) {

}
if (isset($_POST['more'])) {

它应该有用。