为什么我的Instagram加载更多按钮会导致内部服务器错误?

时间:2013-08-05 14:22:04

标签: php jquery ajax laravel instagram

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

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

干杯

1 个答案:

答案 0 :(得分:0)

我最终解决了这个问题。

有一些冲突的php值没有被正确拾取并发送错误的网址。

最后我修改了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
  ));

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

干杯