I am trying to use Cosenary's Instagram Class which is located at.. https://github.com/cosenary/Instagram-PHP-API Specifically, I am trying to do Pagination with a Tag Search. I want it to loop the process until it reach's yesterday's posts. I will run this script daily.
<?php
/**
* Instagram PHP API
*
* @link https://github.com/cosenary/Instagram-PHP-API
* @author Christian Metz
* @since 01.10.2013
*/
require '../dbinclude.php';
require 'Instagram.php';
use MetzWeb\Instagram\Instagram;
// initialize class
$instagram = new Instagram(array(
'apiKey' => '***************',
'apiSecret' => '***************',
'apiCallback' => '*************' // must point to success.php
));
?>
<?php
$i = 0;
$imagecount = 0;
do {
$i++;
echo "Pagination restart";
$photos = $instagram->getTagMedia('kittens');
$result = $instagram->pagination($photos);
foreach($result->data as $post) {
$image = mysqli_real_escape_string($toolconn, $post->images->low_resolution->url);
$caption = mysqli_real_escape_string($toolconn, $post->caption->text);
$author = mysqli_real_escape_string($toolconn, $post->user->username);
$created = mysqli_real_escape_string($toolconn, $post->created_time);
$created = date("Y-m-d H:i:s", $created);
$compare = substr($created, 0, 10);
$twodays = date("Y-m-d",strtotime("-2 days"));
$link = $post->link;
//
echo $twodays . "<br>";
echo $compare . "<Br>";
$sql = "INSERT INTO userfeeds (link, thumbnail, created_at, caption, author)
VALUES ('$link', '$image', '$created', '$caption', '$author')";
// $exec = mysqli_query($toolconn, $sql);
echo $sql . "<br>";
echo "Created; " . $compare . "<BR>";
echo "Comparison; " . $twodays . "</br><hr>";
}
} while ($compare != $twodays);
?>
I have been trying to do this for about three weeks now. For some reason, my loop doesnt work. Help! In the documentation it says the following..
Each endpoint has a maximum range of results, so increasing the limit parameter above the limit won't help (e.g. getUserMedia() has a limit of 90).
That's the point where the "pagination" feature comes into play. Simply pass an object into the pagination() method and receive your next dataset:
<?php
$photos = $instagram->getTagMedia('kitten');
$result = $instagram->pagination($photos);
?>
Iteration with do-while loop.
Basically my end goal is to make sure everyday I didnt miss a post.. I have been trying to work on this for literally three weeks and I have gotten nowhere