Facebook\InstantArticles\Client\Helper::getPagesAndTokens PHP Method

getPagesAndTokens() public method

Returns the set of pages and their associated tokens based on a short-lived user access token.
public getPagesAndTokens ( Facebook\Authentication\AccessToken $accessToken, integer $offset ) : array
$accessToken Facebook\Authentication\AccessToken A short-lived user access token.
$offset integer Offset pages API results
return array
    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();
    }