我正在通过Facebook在我的网站上注册.
I am doing a registration on my website via facebook.
当用户通过Facebook登录时,返回的$ user数组不完全是我想要的.
When the user logs in via facebook the $user array returned is not exactly what i want.
我浏览了可通过Facebook访问的用户参数,我也尝试实现它们,但是它不起作用.
I have gone through the user parameters that are accessible via facebook, i have tried implementing them also but it is not working.
这是我所拥有的样品
require_once "Database_Connect.php"; if (!isset($_POST['choosepassword'])) { # We require the library $user=array(); require("facebook.php"); # my error tracker $error=0; # Creating the facebook object $facebook = new Facebook(array( 'appId' => 'xxx', 'secret' => 'xxx', 'cookie' => true )); # Let's see if we have an active session $session = $facebook->getSession(); if(!empty($session)) { # Active session, let's try getting the user id (getUser()) and user info (api->('/me')) try{ $uid = $facebook->getUser(); $user = $facebook->api('/me'); } catch (Exception $e){} if(!empty($user)){ # User info ok? Let's print it (Here we will be adding the login and registering routines) print_r($user); ***At this point what is retrieved is not exactly what i want***** $ue=$user['email'];$ui=$user['id']; $query = mysql_query("select * from members where email = '$ue' or (oauth_provider = 'facebook' AND oauth_uid = '$ui')", $link); $result = mysql_fetch_array($query); # If not, let's add it to the database if(!empty($result)){ $error = 2; //record already in database require_once "facebook_error.php"; die(); } } else { # For testing purposes, if there was an error, let's kill the script $error = 1; //we were unable to retrieve info frm facebook require_once "facebook_error.php"; die(); } } else { # There's no active session, let's generate one $login_url = $facebook->getLoginUrl(); *** I tried specifying what i want returned here, but it doesnt seem to work***** $url = $facebook->getLoginUrl(array( 'req_perms' => 'uid, first_name, last_name, name, email, current_location, user_website, user_likes, user_interests, user_birthday, pic_big', 'next' => 'www.zzzzzzz/facebook_register.php', 'cancel_url' => 'www.zzzzzzz' )); header("Location: ".$login_url); }我在做什么不对?
谢谢
更新
我现在正在使用FQL从Facebook中选择用户信息,
I am using FQL to select user info from facebook now,
$fql = "select uid, first_name, last_name, name, sex, email, current_location, website, interests, birthday, pic_big from user where uid=me()"; $param = array('method' => 'fql.query', 'query' => $fql, 'callback' => ''); $user = $facebook->api($param);它检索除生日和电子邮件
如何选择电子邮件和生日?
How can i select the email and birthday?
谢谢
推荐答案您的应用程序为此需要user_birthday和email权限,否则它将不返回该信息.您只需要提供需要权限的参数,而不是req_perms参数中想要的字段,所以它应该像这样:
Your application needs the user_birthday and email permissions for this, else it will not return that information. You only need to supply parameters that need a permission, not what fields you want in the req_perms parameter, so it should look like this:
$url = $facebook->getLoginUrl(array( 'req_perms' => 'email, user_birthday', 'next' => 'www.zzzzzzz/facebook_register.php', 'cancel_url' => 'www.zzzzzzz' ));更多推荐
从facebook获取用户信息
发布评论