public function getPagesAndTokens($accessToken, $offset = 0) { Type::enforce($accessToken, 'Facebook\\Authentication\\AccessToken'); // If we don't have a long-lived user token, exchange for one if (!$accessToken->isLongLived()) { try { // The OAuth 2.0 client handler helps us manage access tokens $OAuth2Client = $this->facebook->getOAuth2Client(); $accessToken = $OAuth2Client->getLongLivedAccessToken($accessToken); } catch (FacebookResponseException $e) { throw new FacebookSDKException("Failed to exchange short-lived access token for long-lived access token."); } } // Set this access token as the default $this->facebook->setDefaultAccessToken($accessToken); // Request the list of pages and associated page tokens that are // connected to this user try { $response = $this->facebook->get('/me/accounts?fields=name,id,access_token,supports_instant_articles,picture&offset=' . $offset); } catch (FacebookResponseException $e) { throw new FacebookSDKException('Graph API returned an error: ' . $e->getMessage()); } // Return the array of page objects for this user return $response->getGraphEdge(); }