使用 Facebook PHP SDK v5 获取页面相册列表

Get list of Page Albums using Facebook PHP SDK v5

我想使用 Facebook PHP SDK v5 获取主页的相册列表。

我正在按照 https://developers.facebook.com/docs/graph-api/reference/v2.4/page/albums 上的说明进行操作,具体如下:

/* 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 */

但这似乎不正确,因为 FacebookRequest 中没有“execute”函数 class。

此外,还需要将 access_token 作为第二个变量传递给 FacebookRequest 构造。

我的完整代码如下:

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);

这只会产生

fatal error: Call to undefined method Facebook\FacebookRequest::execute()

有人可以指出正确代码的方向吗?

查看

上的文档

示例代码:

$fbApp = new Facebook\FacebookApp('{app-id}', '{app-secret}');
$request = new Facebook\FacebookRequest($fbApp, '{access-token}', 'GET', '/{page_id}/albums');

// OR

$fb = new Facebook\Facebook(/* . . . */);
$request = $fb->request('GET', '/{page_id}/albums');

// Send the request to Graph
try {
  $response = $fb->getClient()->sendRequest($request);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$graphNode = $response->getGraphNode();

print_r($graphNode);