PHP: Getting list of Facebook 'pages' under an account gets an empty list

196 views Asked by At

I am trying to get the list of FB pages associated with an account. This code has been running successfully for quite a while (a couple of years at least). I am getting no errors either in the javascript console or from PHP. For one of our clients, this code returns an empty array of pages:

// create Facebook objects for API accesses
$this->fb = new Facebook\Facebook([
                'app_id'                => <MY APP ID>,
                'app_secret'            => <MY APP SECRET>
                'default_graph_version' => 'v12.0'
            ]);
$this->fbApp = new Facebook\FacebookApp( <MY APP ID>, <MY APP SECRET> );

// create request for pages
$page_request = new Facebook\FacebookRequest( 
     $this->fbApp, 
     <ACCESS TOKEN>,
     'GET',
     '/me/accounts', 
     [ 'fields' => 'id,name,link,category,access_token',
       'limit' => 10,
       'sort'  => 'name'
     ]
    );
$page_response = $this->fb->getClient()->sendRequest($page_request);

// now get all the "edges" from this response, these will be the page info objects
$facebook_page_list = [];
$feedEdge = $page_response->getGraphEdge();
if ( !empty($feedEdge) )
{
    do
    {
        foreach ($feedEdge as $status )
        {
            $facebook_page = $status->asArray();
            $page = array('name'         => $facebook_page['name'],
                          'id'           => $facebook_page['id'],
                          'category'     => $facebook_page['category'],
                          'access-token' => $facebook_page['access_token'],
                          'page_url'     => $facebook_page['link'],
                          'used'         => false
                          );

            $facebook_page_list[ $page['id'] ] = $page;
        }

        $nextFeed = $this->fb->next($feedEdge);
        $feedEdge = $nextFeed;

    } while ( !empty($feedEdge) );
}

I have a valid access token:

Access Token Info
App ID  <MY APP ID> : iHOUSEListingPoster
Type    User
App-Scoped User ID  : 10218885905922736 : Pennee Lybrook
Data Access Expires 1686662329 (in about 3 months)
Valid   True
Origin  Web
Scopes  email, public_profile

Trying to use that App-Scoped User ID directly in a FB URL (facebook.com/10218885905922736) gets an error page (This content isn't available right now). The account's actual page is at https://www.facebook.com/libbysosinskiKW/ I'm not sure what to make of that. The language gets confusing (Facebook page, VS Pages under an account "page").

Our app lets our clients approve access to their page to post information about their real estate listings as those listings come into our system.

Why do I get an empty list of pages?

0

There are 0 answers