使用Facebook PHP SDK v5获取页面相册列表 [英] Get list of Page Albums using Facebook PHP SDK v5

查看:138
本文介绍了使用Facebook PHP SDK v5获取页面相册列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use Facebook PHP SDK v5 to get a list of photo albums for a Page.

我正在按照 https://developers.facebook.com/docs/graph -api / reference / v2.4 / page / albums ,如下所示:

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.

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

In addition, there also needs to be the access_token passed as the second variable to the FacebookRequest construct.

我的完整代码如下:

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

这只是生成


致命错误:调用未定义的方法
Facebook\FacebookRequest :: execute()

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

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

Can someone point me in the direction of the correct code?

推荐答案

看看

  • https://developers.facebook.com/docs/php/FacebookRequest/5.0.0#overview
  • https://developers.facebook.com/docs/php/gettingstarted/5.0.0#making-requests

示例代码:

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

这篇关于使用Facebook PHP SDK v5获取页面相册列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆