【问题标题】:Add a Load More button to an instagram feed将加载更多按钮添加到 Instagram 提要
【发布时间】:2015-03-19 22:26:24
【问题描述】:

我在网站上有一个有效的 Instagram 供稿。另一个开发人员写了它,我需要添加一个加载更多按钮,以便我们可以看到超过 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" />

【问题讨论】:

  • 您说“不断出现解析错误”——您能向我们展示这些错误吗?否则我们应该如何帮助您?!
  • 错误是 Parse error: syntax error, unexpected $end in /home/three60/public_html/core/cache/includes/elements/modsn-p/57.include.cache.php 在第 49 行

标签: php json instagram instagram-api


【解决方案1】:

您有 4 个左大括号 ({),但只有 3 个右大括号 (})。这就是您收到解析错误的原因。

改变

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

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

它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多