php - How to use Youtube's API V3 pagination features? -


i started using youtube's v3 api , i'm stucked somewhere supposed use pagination not know how that!

i can go next page using nextpagetoken pagetoken can't previous page!

if (!empty($_get['page'])) {     $nopage = $_get['page'];     $page = ($nopage-1)*20;     $pagetoken = $_session["nexttoken"]; } else {     $nopage = 1;     $page = 1; } $searchresponse = $youtube->search->listsearch('id,snippet', array('q' => $q, 'maxresults' => $maxresults, 'type' => "video", 'pagetoken' => $pagetoken,)); if ($nopage > 1) {     //echo'<a href="?page='.($nopage-1).'"><input type="submit" value="&laquo; previous page"/></a> - ';     echo'<a href="'.$vhome.'search.html?q='.querydecode($q).'&amp;page='.$prev.'"><input type="submit" value="&laquo; previous page"/></a> - '; } if ($searchresponse['nextpagetoken']) {     //echo '<a href="?page='.($nopage+1).'"><input type="submit" value="next page &raquo;"/></a>';     echo '<a href="'.$vhome.'search.html?q='.querydecode($q).'&amp;page='.$next.'"><input type="submit" value="next page &raquo;"/></a>'; } 

how results both next , prev page?

a search result page 1 contain "nextpagetoken' ... if set 'pagetoken' parameter, , leave other parameters query same, it'll load page 2.

// loads first page of results $searchresponse = $youtube->search->listsearch('id,snippet', array('q' => $q, 'maxresults' => $maxresults, 'type' => "video")); // gets page 2 of results $newsearchresponse = $youtube->search->listsearch('id,snippet', array('q' => $q, 'maxresults' => $maxresults, 'type' => "video", 'pagetoken' => $searchresponse["nextpagetoken"])); 

page 2 contain 'nextpagetoken' can use go page 3, page 2 returns 'prevpagetoken'; if set 'pagetoken' parameter value , re-run request, you'll results page 1 again.

// loads third page of results $newnewsearchresponse = $youtube->search->listsearch('id,snippet', array('q' => $q, 'maxresults' => $maxresults, 'type' => "video",'pagetoken' => $newsearchresponse["nextpagetoken"])); // goes page 1 of results $oldsearchresponse = $youtube->search->listsearch('id,snippet', array('q' => $q, 'maxresults' => $maxresults, 'type' => "video", 'pagetoken' => $newsearchresponse["prevpagetoken"])); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -