开发者

Facebook backend login

I have been using this same code for so. I tried to use it and it will not let me connect. The front-end javascript one works and my app ids and all that match. Since i want to log in the user i do back end verification (as any sane person would) and in verifyfacebook.php (the stuff your looking at) all the includes are there and i verified that FACEBOOK_APP_ID and SECRET both are correct and they echo out with their values.

I just do not understand what is going on! Anyone see anything i am just missing?

try {
    $facebook = new Face开发者_Go百科book(array(
      'appId'  => FACEBOOK_APP_ID,
      'secret' => FACEBOOK_SECRET_ID,
      'cookie' => true,
    ));

    $session = $facebook->getSession();

    $fbme = null;

    // Session based graph API call.
    if ($session) {
        try {
            $uid = $facebook->getUser();
            $fbme = $facebook->api('/me');
        } catch (FacebookApiException $f) {
        }
    }
} catch (Exception $e) {
}

I just tried to simply the example and it still wont work.

$facebook = new Facebook(array(
  'appId' => FACEBOOK_APP_ID,
  'secret' => FACEBOOK_SECRET_ID,
  'cookies' => true
));

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

echo $uid;

It echos '0'


cookie parameter is no longer used with 3.0.x. Below code did not work until I have removed all cookies, including session ones. redirect_uri is optional, just make sure you get redirected to the same page this code is executed.

$facebook = new Facebook(array(
    'appId' => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_SECRET_ID,
));

$user = $facebook->getUser();

if ( $user )
{
    echo sprintf(
        '<a href="%s">Logout</a>',
         $facebook->getLogoutUrl(array(
            'redirect_uri' => URL,
         ))
    );
}
else
{
    echo sprintf(
        '<a href="%s">Login</a>',
         $facebook->getLoginUrl(array(
            'redirect_uri' => URL,
            'scope'        => SCOPE,
         ))
    );
}

if ( $user )
{
    try
    {
        print_r($facebook->api('/me');
    }
    catch ( FacebookApiException $e )
    {
        print_r($e);
    }
}


This post should help:

http://developers.facebook.com/blog/post/525/

Try and implement the code as is, then once you get it working you can customise it to your needs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜