使用PHP在我的网站上登录facebook [英] login wiht facebook in my website using PHP

查看:198
本文介绍了使用PHP在我的网站上登录facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ facebook-> getuser()总是返回0

我检查了许多网站的解决方案但没有得到任何解决方案



这是我的代码:

 include_once   facebook-php-sdk -master / SRC / facebook.php; 
// 初始化
$ config = array(
' appId' => myappid'
' secret' => ' myappsecret'
' cookie' => true
);

$ facebook = new Facebook($ config);
// 获取用户ID
$ uid = $ facebook-> getUser();
if($ uid)
{
echo $ uid ;
$ params = array(' next' => $ currentUrl );
$ logoutUrl = $ facebook-> getLogoutUrl($ params); // $ params是可选的
echo < a target = _blank href = $ logoutUrl >从FB退出< / a>;
// $ facebook-> destroySession();
尝试
{
$ user_profile = $ facebook-> api(' / me'' GET');
echo 名称:。 $ user_profile [' name'];
}
catch(FacebookApiException $ e)
{
echo ERROR;
}
}
else
{
// 如果用户未登录,则获取登录用户
$ params =数组(
' scope' => ' read_stream,friends_likes,email'
' redirect_uri' => ' http://www.comettea.com'
' display' => ' popup'
);

$ loginUrl = $ facebook-> getLoginUrl($ params);
echo $ loginUrl。 < br />中;
echo < a target = _blank href =。$ loginUrl。 >登录FB< / a>;
}





请帮助

解决方案

facebook-> ; getuser()总是返回0

我检查了许多网站的解决方案但没有得到任何解决方案



这是我的代码:

 include_once   facebook-php-sdk -master / SRC / facebook.php; 
// 初始化


config = array(
' appId' => ' myappid'
' secret' => ' myappsecret'
' cookie' => true
);


facebook = new Facebook的(

$facebook-> getuser() always returns 0
I checked many websites for solution but not get any solution

This is my code:

include_once "facebook-php-sdk-master/src/facebook.php";
//initializing
$config = array(
      'appId' => 'myappid',
      'secret' => 'myappsecret',
	  'cookie' => true
  );

  $facebook = new Facebook($config);
  //getting user id 
  $uid = $facebook->getUser();
  if($uid)
  	{
		echo $uid;
		$params = array( 'next' => $currentUrl );
		$logoutUrl=$facebook->getLogoutUrl($params); // $params is optional
		echo "<a target="_blank" href="$logoutUrl">Logout from FB</a>";
		//$facebook->destroySession();
		try
		{
			$user_profile = $facebook->api('/me','GET');
       		echo "Name: " . $user_profile['name'];
		}
		catch(FacebookApiException $e)
		{
			echo "ERROR";
		}
	 }
  else
  	{
		//if user is not logged in then get the login user
		$params = array(
			  'scope' => 'read_stream, friends_likes, email',
			  'redirect_uri' => 'http://www.comettea.com',
			  'display' => 'popup',
				);

		$loginUrl = $facebook->getLoginUrl($params);
		echo $loginUrl."<br />";
		echo "<a target="_blank" href=".$loginUrl."> Login in FB </a>";
	}



please help

解决方案

facebook-> getuser() always returns 0
I checked many websites for solution but not get any solution

This is my code:

include_once "facebook-php-sdk-master/src/facebook.php";
//initializing


config = array( 'appId' => 'myappid', 'secret' => 'myappsecret', 'cookie' => true );


facebook = new Facebook(


这篇关于使用PHP在我的网站上登录facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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