如何在PHP

时间:2016-07-13 07:46:38

标签: php facebook

我想通过使用Facebook PHP SDK获取一些Facebook用户详细信息。

这是我的配置文件:

include_once("inc/facebook.php"); //include facebook SDK
$appId = 'appid'; //Facebook App ID
$appSecret = 'appsecret'; // Facebook App Secret
$homeurl = 'http://my home url';  //return to home
$fbPermissions = 'email';  //Required facebook permissions    
//Call Facebook API
$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $appSecret
));
$fbuser = $facebook->getUser();

这是我用来调用它的代码示例,但我无法从Facebook获取用户详细信息。

if(isset($fbuser)  && $fbuser != null)
{
    $user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
    $user = new Users();

    $user_data = $user->checkUser('facebook',$user_profile['id'],$user_profile['first_name'],$user_profile['last_name'],$user_profile['email'],$user_profile['gender'],$user_profile['locale'],$user_profile['picture']['data']['url']);
    if(!empty($user_data)){
       $_SESSION['USERID'] = $user_data['cid'];
       $_SESSION['FIRSTNAME'] = $user_data['cname'];
       $_SESSION['EMAIL'] = $user_data["email"];
      header('Location:index.php');
    }else{
         $output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
    }
}else
{
    header('Location:login.php');
}

0 个答案:

没有答案