0

我正在 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

有谁知道为什么它不会产生结果?我知道它不会太远。

干杯

4

1 回答 1

0

我最终解决了这个问题。

有冲突的 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
  ));

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

干杯

于 2013-08-06T10:42:57.420 回答