Jump to content

Recommended Posts

I am building a relatively small app in laravel.

Currently I am trying to create a load more button to load more images into a container in the view.

Would anyone know when clicking load more I get an internal server error?

Here is my set up:

View for my images:

$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>';

Here the instagram class generates the images and puts them into the div through a loop. Below is a load more button storing the data need in it.

Load more button:

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

And then there is an ajax view that stores the relevant data for the images to be found for the next page:

<?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
));

This page finds the tag and gets the media for that tag and finds the next_max_id. In my jquery I use and ajax call to get this data and load the images into my div but instead I get an internal server error like so:

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

Does anyone have an idea why it would not produce the results? I know its not too far off.

 

Thanks,

Mark

ajax.blade.php

image.blade.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.