Jump to content

markdunbavan

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by markdunbavan

  1. Hello, I am trying to create an array where by the items listed are nested with the names and the array spat out is easy to use when I am creating an ajax function with data from it all. Below is an idea of what I need to do: # This is where I am grabbing the data from the instagram class $data_url[] = $data->images->standard_resolution->url; $data_link[] = $data->link; $data_id[] = $data->getId(); $data_likes[] = $data->likes->count; {["images":[ ["data_url":[ ["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg"] ], ["data_link":[ ["http:\/\/instagram.com\/p\/cq2pjLMNNE\/"] ], ["data_id": [516465457066201924_288233123] ], ["data_likes": [18] ] ] ] } In my current ajax.php page, I am creating a place where data can be captured and I can use it to get the images and place them into a page. Here is what I have got so far: $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(); $data_link = array(); $data_id = array(); $data_likes = array(); foreach ($media as $data) { $images[] = array($data_url[] = $data->images->standard_resolution->url,$data_link[] = $data->link, $data_id[] = $data->getId(), $data_likes[] = $data->likes->count); } echo json_encode(array( 'next_id' => $media->getNextMaxTagId(), 'images' => $images )); Below is what my /ajax/ url gives me: {"next_id":"1374887530845","images":[["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg","http:\/\/instagram.com\/p\/cq2pjLMNNE\/","516465457066201924_288233123",18],["http:\/\/distilleryimage10.s3.amazonaws.com\/46f790e0fdaf11e29de622000ae90e7b_7.jpg","http:\/\/instagram.com\/p\/coEUD0MyGO\/","515681128006492558_197168271",23],["http:\/\/distilleryimage6.s3.amazonaws.com\/7e510fa6fcee11e29a4b22000a1fb593_7.jpg","http:\/\/instagram.com\/p\/clmYo1AgU6\/","514986551277651258_20025128",25],["http:\/\/distilleryimage0.s3.amazonaws.com\/4f41be96fc3411e2829822000a9f1487_7.jpg","http:\/\/instagram.com\/p\/cjN3PipYkE\/","514315753313634564_190097401",10],["http:\/\/distilleryimage0.s3.amazonaws.com\/bcc8d83cfb9911e2921e22000aa81fd0_7.jpg","http:\/\/instagram.com\/p\/chPPNdGDhI\/","513758848433535048_6206549",13],["http:\/\/distilleryimage2.s3.amazonaws.com\/ef97af2efb5611e2b16122000a1f9e61_7.jpg","http:\/\/instagram.com\/p\/cgYg4ljpby\/","513518170419402482_52465932",1],["http:\/\/distilleryimage5.s3.amazonaws.com\/8e7bbf04fa9e11e2aea022000a9d0ee7_7.jpg","http:\/\/instagram.com\/p\/ceBeGXNpA9\/","512853874029531197_20203491",2],["http:\/\/distilleryimage4.s3.amazonaws.com\/96dc4444f9f811e2b88d22000a1fd1dd_7.jpg","http:\/\/instagram.com\/p\/cb5gooAgW4\/","512255913931965880_20025128",6],["http:\/\/distilleryimage11.s3.amazonaws.com\/6b80e884f9dc11e29b2522000a9f13d5_7.jpg","http:\/\/instagram.com\/p\/cbibv3JW9H\/","512154423034998599_430907394",20],["http:\/\/distilleryimage7.s3.amazonaws.com\/64f82bd6f95411e2a73522000a1faf50_7.jpg","http:\/\/instagram.com\/p\/cZzAF8syFb\/","511664339442409819_197168271",16],["http:\/\/distilleryimage10.s3.amazonaws.com\/b54645f4f93711e283e622000a1fb86d_7.jpg","http:\/\/instagram.com\/p\/cZbgGrlSzW\/","511560986135964886_187431354",17],["http:\/\/distilleryimage8.s3.amazonaws.com\/a9fc18a2f87111e29c8b22000a9f18f4_7.jpg","http:\/\/instagram.com\/p\/cW5Q5CBrlw\/","510847457153169776_378485429",6],["http:\/\/distilleryimage0.s3.amazonaws.com\/55b6269cf86311e2b5f422000a1f9a34_7.jpg","http:\/\/instagram.com\/p\/cWthoKit5E\/","510795830715407940_203990694",16],["http:\/\/distilleryimage9.s3.amazonaws.com\/bff691e2f82a11e2939b22000a1f9251_7.jpg","http:\/\/instagram.com\/p\/cV_K8mBu9R\/","510591961963884369_256035442",12],["http:\/\/distilleryimage4.s3.amazonaws.com\/5ef4c3c0f73811e2890322000a9e48f1_7.jpg","http:\/\/instagram.com\/p\/cS4nTwwE_U\/","509718699729506260_37194114",34],["http:\/\/distilleryimage8.s3.amazonaws.com\/a1b5f0acf6cb11e2957722000a1f9a39_7.jpg","http:\/\/instagram.com\/p\/cRfiPgmAWQ\/","509326925426591120_453101536",11],["http:\/\/distilleryimage6.s3.amazonaws.com\/4bf62240f68511e29aee22000a9f38e6_7.jpg","http:\/\/instagram.com\/p\/cQl6qiBzdu\/","509073517011482478_5670460",223],["http:\/\/distilleryimage1.s3.amazonaws.com\/d23848d6f61e11e2807c22000a9e06c7_7.jpg","http:\/\/instagram.com\/p\/cPR9_otpGt\/","508704309923713453_20203491",6]]} Can anyone guide me into the best way I can do this so it gives me an array from my ajax.php so I can grab the data and place it into my page better? I have tried numerous techniques but they have not worked at all. Thanks, Mark
  2. 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
×
×
  • 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.