skip to Main Content

From here: https://developers.facebook.com/docs/graph-api/reference/user/accounts/ I got to write this in my code

$request = new FacebookRequest(
             $session,
             'GET',
             '/{user-id}/accounts'
           );

$response = $request->execute();

The problem here is with version 2.8 of the API and SDK 5.0 execute() doesn’t exist. How can I get a list of all the pages on a Facebook account.

2

Answers


  1. Chosen as BEST ANSWER

    @JayNCoke was correct with the approach.

    $fb = new FacebookFacebook([
      'app_id' => '{app-id}',
      'app_secret' => '{app-secret}',
      'default_graph_version' => 'v2.5',
    ]);
    
    // Sets the default fallback access token so we don't have to pass it to each request
    $fb->setDefaultAccessToken('{access-token}');
    
    $response = $fb->get('{user-id}/accounts');
    

    $response returns a FacebookFacebookResponse object

    To get it in a usable data format, just call getDecodedBody() like below

    $response = $response->getDecodedBody();
    

    This returns an array.


  2. You have the right endpoint, you just need to make sure you have the right call in PHP:

    $fb = new FacebookFacebook([
      'app_id' => '{app-id}',
      'app_secret' => '{app-secret}',
      'default_graph_version' => 'v2.5',
    ]);
    
    // Sets the default fallback access token so we don't have to pass it to each request
    $fb->setDefaultAccessToken('{access-token}');
    
    $response = $fb->get('{user-id}/accounts');
    

    Also remember:

    • You’ll need to make sure your app is asking for the manage_pages permission.
    • This only returns pages that the user is an Admin on. If they are of any other role, it won’t return that page.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search