开发者

Facebook application "if empty session" not working, how can I fix it?

开发者 https://www.devze.com 2023-02-09 21:58 出处:网络
This is the code I am using to hopefully create a very simple app on facebook to say \"Hello (name)\" however I get the error \"An error occoured\".

This is the code I am using to hopefully create a very simple app on facebook to say "Hello (name)" however I get the error "An error occoured".

<?php

require "facebook.php";

// create application instance
$facebook = new Facebook(array(
'appId' => '********************************',
'secret' => '********************************',
'cookie' => true,
));

$session = $facebook->getSession();

if (!empty($session)) {
        try {
            $uid = $facebook->getUser();
            $user = $facebook->api('/me');
        } catch (exception $e) {}

    if (!empty($user))
    {
        if($_GET['installed']=='1') {
            header("Location: http://apps.facebook.com/gamerimg/");
        }

        echo "Hello ".$user['first_name'];
    } else {
        die("An error occoured!");
    }
} else {

    $url = $facebook->getLoginUrl();
    echo "<a href='".$url."'>Click here</a> to add the GamerImg Facebook applicatio开发者_如何转开发n.";

}

?>

I am very new to fbml so I have no idea what to do! How can I fix it?!

It's probably something to do with this line: $user = $facebook->api('/me');


Most likely your Facebook calls are throwing an exception, but you catch the exception and keep going. Normally you'd put the die call inside the catch block, and the if block inside the try block.

And if you put the die call inside the try block, I'd change it to die("An error occurred! ".$e->getMessage()); so you can see what the error message is.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号