在尝试将Faceboook PHP SDk从v4迁移到v5时,我收到错误:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method Facebook\Helpers\FacebookPageTabHelper::getSession()
v5中缺少getSession()
方法。
如何在v5中替换getSession()方法?
使用v4,我必须设置APP_ID和APP_SECRET,如:
include_once('assets/facebook/autoload.php');
FacebookSession::setDefaultApplication(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET);
然后我就像这样初始化FacebookPageTabHelper
类:
$helper = new FacebookPageTabHelper();
然后我有了代码:
$helper = $fb->getPageTabHelper();
if ($helper->getPageId()) {
$data['page'] = [
'id' => $helper->getPageId(),
'admin' => $helper->isAdmin(),
'liked' => false
];
}
/* IF PAGE SESSION AUTO LOGIN USER */
if ($helper->getSession()) {
$session = $helper->getSession();
}
在v5中,我这样做:
require_once('assets/facebook/facebook-php-sdk-v-5/autoload.php');
$fb = new Facebook\Facebook(
[
'app_id' => FACEBOOK_APP_ID,
'app_secret' => FACEBOOK_APP_SECRET,
'default_graph_version' => 'v2.8',
]
);
$helper = $fb->getPageTabHelper();
if ($helper->getPageId()) {
$data['page'] = [
'id' => $helper->getPageId(),
'admin' => $helper->isAdmin(),
'liked' => false
];
}
* IF PAGE SESSION AUTO LOGIN USER */
if ($helper->getSession()) {
$session = $helper->getSession();
}