我正在尝试使用PHP SDK从Facebook页面读取评级以在外部显示。我已经拥有一个长实时访问令牌,并且能够使用它来提取主页面数据,但是当我尝试访问/ratings
端点时,我只收到一个空的Array ( )
class FacebookReviews
{
protected $session;
protected $page;
protected $ratings;
protected $appId;
protected $appSecret;
function __construct($appId = null, $appSecret = null)
{
session_start();
$this->appId = '123456789123456';
$this->appSecret = '1234567890abcdefghijklmnopqrstuv';
Facebook\FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$this->session = new Facebook\FacebookSession('LONG LIVE ACCESS TOKEN I GENERATED ON THE GRAPH API');
try {
$this->session->validate();
} catch (Facebook\FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
echo $ex->getMessage();
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
echo $ex->getMessage();
}
try {
$this->page = (new Facebook\FacebookRequest($this->session, 'GET', '/123456789123456/ratings'))->execute()->getGraphObject()->asArray();
} catch(Facebook\FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
public function result()
{
return $this->page;
}
}
$reviews = new FacebookReviews();
print_r($reviews->result());
如果我从请求uri中删除/ratings
,它会返回数据,但正如我在那里提到的那样,它不起作用。
我从自己的帐户生成了长期访问令牌,该帐户具有对该页面的管理员权限