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="« previous page"/></a> - '; echo'<a href="'.$vhome.'search.html?q='.querydecode($q).'&page='.$prev.'"><input type="submit" value="« previous page"/></a> - '; } if ($searchresponse['nextpagetoken']) { //echo '<a href="?page='.($nopage+1).'"><input type="submit" value="next page »"/></a>'; echo '<a href="'.$vhome.'search.html?q='.querydecode($q).'&page='.$next.'"><input type="submit" value="next page »"/></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
Post a Comment