PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, March 13, 2022

[FIXED] How can I get the pages that a Facebook account has with SDK 5.0?

 March 13, 2022     api, facebook, facebook-graph-api, facebook-php-sdk     No comments   

Issue

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.


Solution

@JayNCoke was correct with the approach.

$fb = new Facebook\Facebook([
  '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 Facebook\FacebookResponse object

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

$response = $response->getDecodedBody();

This returns an array.



Answered By - Oladipo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing