FaceBook SDK Query (Until and Since): Solved

FaceBook SDK Query (Until and Since), It’s Difficult to understand from the documentation of FaceBook SDK, The Following code, Clears the Confusion.

Using: say Since=10-06-2015 to get All Post from Today till 10-06-2015, the Result is from 10 June till today hence Next goes front till Today is reached.

// using fb Query 
// /feed?limit=100&fields=id,from,picture,updated_time,created_time&with=picture&since='.strtotime($weekback)
//$weekback = dd-mm-yyyy
do {
	//echo 'Loop' . ++$loopCnt . '<br /><br />';
	//var_dump($request);
	// echo '<br /><br />';
        // Loop Counter to exit if error set $loopCnt to 1,5 
	++$loopCnt;
	$response = $request->execute();
	$graphObject = $response->getGraphObject();
/*
	?>
	   <pre>
		<?php var_dump($graphObject->getProperty('data')); ?>
	   </pre>
	<?php
*/
	// $graphObject->getProperty('data') return "NULL" when no Next Page Exist: Reached the Start of Data.
        if ( $graphObject->getProperty('data') ) {
		$some_post = $graphObject->getProperty('data')->asArray();
		$tsk_post = array_merge($tsk_post, $some_post);
	}
	if ( $loopCnt > $maxPageGet ) { break; }
			//usleep(2000);
} while ($request = $response->getRequestForNextPage());

Using: say Until=10-06-2015 to get All Post from infinity till 10-06-2015, the Result is from 10-06-2015 hence Previous goes back till start date is reached.

// using fb Query 
// /feed?limit=100&fields=id,from,picture,updated_time,created_time&with=picture&until='.strtotime($weekback)
//$weekback = dd-mm-yyyy
do {
	//echo 'Loop' . ++$loopCnt . '<br /><br />';
	//var_dump($request);
	// echo '<br /><br />';
        // Loop Counter to exit if error set $loopCnt to 1,5 
	++$loopCnt;
	$response = $request->execute();
	$graphObject = $response->getGraphObject();
/*
	?>
	   <pre>
		<?php var_dump($graphObject->getProperty('data')); ?>
	   </pre>
	<?php
*/
	// $graphObject->getProperty('data') return "NULL" when no Next Page Exist: Reached the Start of Data.
        if ( $graphObject->getProperty('data') ) {
		$some_post = $graphObject->getProperty('data')->asArray();
		$tsk_post = array_merge($tsk_post, $some_post);
	}
	if ( $loopCnt > $maxPageGet ) { break; }
			//usleep(2000);
} while ($request = $response->getRequestForPreviousPage());

Hope its Clear.. Once I finish on this project I shall post the tutorial

 

Posted in FaceBook and tagged , , , , .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.