Facebook后端登录 [英] Facebook backend login

查看:185
本文介绍了Facebook后端登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用相同的代码。我试图使用它,它不会让我连接。前端的JavaScript一个工作,我的应用程序ids和所有匹配。因为我想登录用户我做后端验证(任何理智的人)和在verifyfacebook.php(你看的东西)所有的包括在那里,我验证了FACEBOOK_APP_ID和SECRET都是正确的,他们回声与他们的价值观。



我只是不明白发生了什么!
任何人看到我刚刚失踪的东西?

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

$ session = $ facebook-> getSession();

$ fbme = null;

//基于会话的图API调用。
if($ session){
try {
$ uid = $ facebook-> getUser();
$ fbme = $ facebook-> api('/ me');
} catch(FacebookApiException $ f){
}
}
} catch(异常$ e){
}






我只是试图简单的说明,它仍然无法工作。

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

//获取用户ID
$ uid = $ facebook-> getUser();

echo $ uid;

它回显0

解决方案

cookie 参数不再与3.0.x一起使用。以下代码在我删除了所有的cookies之前没有工作,包括会话。 redirect_uri 是可选的,只需确保您重定向到执行代码的同一页。

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

$ user = $ facebook-> getUser();

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

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


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 Facebook(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);
    }
}

这篇关于Facebook后端登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆