Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing PHP to store json via Instagram API
    primarykey
    data
    text
    <p>I feel like I'm overthinking this. What I want to do is pull the most recent photos from the instagram api and save the resulting json information as a cache file. I'll then use jQuery to read from that file -- I've got that part figured out. What I'm using now is saving it in a cache file, but not in a format that I recognize. I think I'm overcomplicating this.</p> <p>This is code I've been working with based on a tutorial I found:</p> <pre><code>// Client ID for Instagram API $instagramClientID = '9110e8c268384cb79901a96e3a16f588'; $api = 'https://api.instagram.com/v1/media/popular?client_id='.$instagramClientID; //api request (edit this to reflect tags) $cache = 'cache.txt'; if(file_exists($cache) &amp;&amp; filemtime($cache) &gt; time() - 60*60){ // If a cache file exists, and it is newer than 1 hour, use it $images = unserialize(file_get_contents($cache)); } else{ // Make an API request and create the cache file // For example, gets the 32 most popular images on Instagram $response = file_get_contents($api); //change request path to pull different photos $images = array(); // Decode the response and build an array foreach(json_decode($response)-&gt;data as $item){ // Decodes json (javascript) into an array $title = ''; if($item-&gt;caption){ $title = mb_substr($item-&gt;caption-&gt;text,0,70,"utf8"); } $src = $item-&gt;images-&gt;standard_resolution-&gt;url; //Caches standard res img path to variable $src $lat = $item-&gt;data-&gt;location-&gt;latitude; // Caches latitude as $lat $lon = $item-&gt;data-&gt;location-&gt;longtitude; // Caches longitude as $lon $images[] = array( "title" =&gt; htmlspecialchars($title), "src" =&gt; htmlspecialchars($src), "lat" =&gt; htmlspecialchars($lat), "lon" =&gt; htmlspecialchars($lon) // Consolidates variables to an array ); } // Remove the last item, so we still have // 32 items when when the cover is added //array_pop($images); // Push the cover in the beginning of the array //array_unshift($images,array("title"=&gt;"Cover", "src"=&gt;"assets/img/cover.jpg")); // Update the cache file file_put_contents($cache,serialize($images)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload