为什么我的Instagram加载更多按钮不断抛出内部服务器错误


Why does my Instagram load more button keep throwing internal server error?

我正在laravel中构建一个相对较小的应用程序。

目前,我正在尝试创建一个加载更多按钮,将更多图像加载到视图中的容器中。

有人知道当点击加载更多时我会得到一个内部服务器错误吗?

这是我的设置:

查看我的图像:

$instagram = new Instagram'Instagram;
    $instagram->setAccessToken($_SESSION['instagram_access_token']);
    $token = $_SESSION['instagram_access_token'];
    //$clientID = $_SESSION['client_id'];
    $current_user = $instagram->getCurrentUser();
    $tag = $instagram->getTag('folkclothing');
    $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null);

    $liked_media = $current_user->getLikedMedia();
echo '<section id="images">';
    foreach ( $media as $item ) {
        echo '<article class="instagram-image">';
        // define the form and set the action to POST to send the data to this script
        echo '<form class="forms" action="'; echo URL::current(); echo '" method="post">';
            $id = $item->getId();
            echo '<a class="fancybox" href="' . $item->link . '"><img src="' . $item->images->standard_resolution->url . '" /></a>';
            if ( $current_user->likes($item) ){
                echo '<button class="ajax instabtn unlike icon-heart" type="submit" name="action" value="Unlike"></button>';
            } else {
                echo '<button class="ajax instabtn like icon-heart" type="submit" name="action" value="Like"></button>';
            }
            echo '<input type="hidden" name="id" value="'; echo $id; echo '">';
            echo '<p>'; echo $item->likes->count; echo '</p>';
            //echo '<p>'.$item->getId().'</p>';
            //echo '<p>By: <em>' . $item->user->username . '</em> </p>';
            //echo '<p>Date: ' . date('d M Y h:i:s', $item->created_time) . '</p>';
            //echo '<p>$item->comments->count . ' comment(s). ' . $item->likes->count . ' likes. ';
        echo '</form>';
        echo '</article>';
    }
    echo '</section>';

在这里,instagram类生成图像,并通过循环将它们放入div中。下面是一个加载更多按钮,其中存储了所需的数据。

加载更多按钮:

echo "<br><button id='"more'" data-maxid='"{$media->getNextMaxTagId()}'" data-tag='"{$tag}'">Load more ...</button>";

然后是一个ajax视图,它存储了下一页要查找的图像的相关数据:

<?php
// set up autoloader
function app_autoloader($class) {
  include './' . $class . '.php';
}
spl_autoload_register('app_autoloader');
 // Initialize class for public requests
  $instagram = new Instagram'Instagram;
  // Receive AJAX request and create call object
  $tag = $_GET['tag'];
  $clientID = $instagram->getApiKey();

  $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null);
  $call = new stdClass;
  $call->next_max_id = $maxID;
  $call->next_url = "https://api.instagram.com/v1/tags/{$tag}/media/recent?client_id={$clientID}&max_tag_id={$media->getNextMaxTagId()}";
  // Receive new data
  $media = $instagram->pagination($call);
  // Collect everything for json output
  $images = array();
  foreach ($media->data as $data) {
    $images[] = $data->images->standard_resolution->url;
  }
  echo json_encode(array(
    'next_id' => $media->getNextMaxTagId,
    'images'  => $images
  ));

此页面查找标签并获取该标签的媒体并查找next_max_id。在我的jquery中,我使用ajax调用来获取这些数据并将图像加载到我的div中,但我得到了一个内部服务器错误,如下所示:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://client:8888/ajax?tag=client&max_tag_id=1374869525975&_=137571153802

有人知道为什么它不会产生结果吗?我知道离这儿不远。

干杯

我最终解决了这个问题。

有一些冲突的php值没有被正确地提取,并发送了错误的url来传递。

最后,我修改了ajax页面,如下所示:

<?php
// set up autoloader
function app_autoloader($class) {
  include './' . $class . '.php';
}
spl_autoload_register('app_autoloader');
// start session
session_start();
if (!isset( $_SESSION['instagram_access_token'] ) ) {
$auth = new Instagram'Auth( $auth_config );
if (isset($_GET['code'])) {
      $_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );
      header( 'Location: ' . REDIRECT_AFTER_AUTH );
      exit;
  } else {
    $auth->authorize();
  }
  exit;
}

  $instagram = new Instagram'Instagram;
  $instagram->setAccessToken($_SESSION['instagram_access_token']);
  $token = $_SESSION['instagram_access_token'];
    //$clientID = $_SESSION['client_id'];
  $current_user = $instagram->getCurrentUser();
  $tag = $instagram->getTag('folkclothing');
  $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null);
/*   $params = isset( $_GET['max_tag_id'] ) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null; */
  /* $media = $tag->getMedia($params); */
  /* $next_page = $media->getNext(); */
/*
  // Receive new data
  $imageMedia = $instagram->pagination($media);
*/
  // Collect everything for json output
  $images = array();
  foreach ($media as $data) {
    $images[] = array($data->images->standard_resolution->url,$data->link,$data->getId(),$data->likes->count);
  }
  echo json_encode(array(
    'next_id' => $media->getNextMaxTagId(),
    'images'  => $images
  ));

我希望这能帮助任何想在这里做同样事情的人:)

干杯