Facebook-php-sdk

发布于 2024-12-04 02:38:24 字数 1074 浏览 1 评论 0原文

所以我使用 facebook-php-sdk 并且创建了一个页面选项卡 在页面选项卡上,我尝试使用 SDK,它仅在我以页面而非用户身份登录 facebook 时才有效,那么造成这种情况的原因是什么?

require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
    'appId'  => '//APP ID//',
    'secret' => '//APP SECRET//',
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } 
    catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

if(isset($user)) {
    var_dump($user); 
}
else if(isset($user_profile)) {
    var_dump($user_profile);
}
else {
    echo $loginUrl;
}


var_dump($facebook->getUser());

我得到的是 error_log: Bad Signed JSON 签名

So I am using the facebook-php-sdk and I have created a page tab
On the page tab I am trying to use the SDK and it only works when I have logged into facebook as the page not as a user so what would the cause of this be?

require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
    'appId'  => '//APP ID//',
    'secret' => '//APP SECRET//',
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } 
    catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

if(isset($user)) {
    var_dump($user); 
}
else if(isset($user_profile)) {
    var_dump($user_profile);
}
else {
    echo $loginUrl;
}


var_dump($facebook->getUser());

I get this is the error_log: Bad Signed JSON signature

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2024-12-11 02:38:24

您正在测试的用户是否已连接到该页面(即,喜欢它)?否则,您将不会收到有关用户身份的任何信息。这是可以预料的。当用户没有明确喜欢该页面时,Facebook 会尽力匿名化用户与页面应用程序的交互。

Is the user you are testing with connected to the page (i.e., Liked it)? If not you will not receive any information about who the user is. This is to be expected. Facebook does its best to anonymize the user interaction with pages' apps when the user hasn't explicitly Liked the page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文