public function testPaginationReturnsProperResponse() { $config = array_merge($this->config, ['http_client_handler' => new FooClientInterface()]); $fb = new Facebook($config); $request = new FacebookRequest($fb->getApp(), 'foo_token', 'GET'); $graphEdge = new GraphEdge($request, [], ['paging' => ['cursors' => ['after' => 'bar_after_cursor', 'before' => 'bar_before_cursor']]], '/1337/photos', '\\Facebook\\GraphNodes\\GraphUser'); $nextPage = $fb->next($graphEdge); $this->assertInstanceOf('Facebook\\GraphNodes\\GraphEdge', $nextPage); $this->assertInstanceOf('Facebook\\GraphNodes\\GraphUser', $nextPage[0]); $this->assertEquals('Foo', $nextPage[0]['name']); $lastResponse = $fb->getLastResponse(); $this->assertInstanceOf('Facebook\\FacebookResponse', $lastResponse); $this->assertEquals(1337, $lastResponse->getHttpStatusCode()); }
<?php require_once __DIR__ . '/vendor/autoload.php'; use Facebook\Facebook; $allalbums = array(); $fb = new Facebook(['app_id' => '177197009081544', 'app_secret' => '64a6d7830db5893985cbe0475ce5a9db', 'default_graph_version' => 'v2.4', 'default_access_token' => '177197009081544|64a6d7830db5893985cbe0475ce5a9db']); //get first page $fb->get('rolandgarros/albums'); $nextpage = true; while ($nextpage) { $something = $fb->getLastResponse(); $items = $something->getDecodedBody()['data']; if (count($items)) { $allalbums = array_merge($allalbums, $items); } //get next page $nextpage = $fb->next($something->getGraphEdge()); } header('content-type: Application/json'); echo json_encode($allalbums);