I want to use Facebook PHP SDK v5 to get a list of photo albums for a Page.
I am following the instructions at https://developers.facebook.com/docs/graph-api/reference/v2.4/page/albums, which are as follows:
/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/{page-id}/albums'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
This does however seem to be incorrect as there is no "execute
" function in the FacebookRequest class.
In addition, there also needs to be the access_token
passed as the second variable to the FacebookRequest
construct.
My full code is as follows:
require_once("classes/Facebook/autoload.php");
use Facebook\Facebook;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
$config = array();
$config['app_id'] = '{app_id}';
$config['app_secret'] = '{secret}';
$config['default_graph_version'] = 'v2.4';
$fb = new Facebook($config);
$app= new FacebookApp($config['app_id'],$config['app_secret']);
$request=new FacebookRequest($app,"{access_token}",'GET','/{page_id}/albums');
$response = $request->execute();
$graphObject = $response->getGraphObject();
print_r($graphObject);
This just produces the
fatal error: Call to undefined method Facebook\FacebookRequest::execute()
Can someone point me in the direction of the correct code?