Facebook后端登录 [英] Facebook backend login
问题描述
我只是不明白发生了什么!
任何人看到我刚刚失踪的东西?
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屋!