我在我的网站上有一个Facebook Connect登录,我用它来获取有关我的用户的一些数据。我想知道的一件事是用户是否已经过Facebook验证。我在文档中将其视为“已验证”值。当用户授权我的应用程序时,我已经要求一些基本的访问参数,所以我认为我应该能够访问它。但是当我尝试返回值时,我得到一个空值。
我的代码是这样的:
if ($facebook->getSession()) {
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} else {
$params = array(
'fbconnect'=>0,
'canvas'=>1,
'req_perms'=>'email,user_birthday,user_location,user_about_me'
);
$birthday=$fbme['birthday'];
echo "Birthday=$birthday"; //This works
$verified=$fbme['verified'];
echo "Verified=$verified"; //This just shows nothing.
好的,vardump给了我以下内容。我在那里看到它。我想我现在必须弄清楚如何提取它。 (别担心,这是一个测试用户,我已经更改了一些数据,所以我不会在这里公开任何个人信息)
用户#1(已返回验证值):
{ ["id"]=> string(10) "1503999261" ["name"]=> string(12) "Monique Bush"
["first_name"]=> string(7) "Shane" ["last_name"]=> string(4) "Bush" ["link"]=> string(49)
"http://www.facebook.com/profile.php?id=1503999221" ["birthday"]=> string(10) "02/17/1974"
["hometown"]=> array(2) { ["id"]=> string(0) "" ["name"]=> NULL } ["location"]=> array(2)
{ ["id"]=> string(0) "" ["name"]=> NULL } ["bio"]=> string(24) "I just like to have fun!"
["gender"]=> string(6) "female" ["email"]=> string(22) "myemail@gmail.com"
["timezone"]=> int(-5) ["locale"]=> string(5) "en_US" ["verified"]=> bool(true)
["updated_time"]=> string(24) "2011-04-17T14:24:16+0000" } fbid=1503999221
用户#2 :(根本没有返回。甚至不是假的)
{ ["id"]=> string(15) "100003353106485" ["name"]=> string(14) "Randy Mason"
["first_name"]=> string(5) "Randy" ["last_name"]=> string(8) "Mason" ["link"]=>
string(54) "http://www.facebook.com/profile.php?id=100003353106485" ["birthday"]=>
string(10) "02/05/1985" ["work"]=> array(1) { [0]=> array(1) { ["employer"]=> array(2)
{ ["id"]=> string(15) "107572525938726" ["name"]=> string(3) "IBM" } } }
["education"]=> array(2) { [0]=> array(3) { ["school"]=> array(2) { ["id"]=> string(15)
"107705972591905" ["name"]=> string(55) "Thomas Jefferson High School for Science and
Technology" } ["year"]=> array(2) { ["id"]=> string(15) "194603703904595" ["name"]=>
string(4) "2003" } ["type"]=> string(11) "High School" } [1]=> array(3) { ["school"]=>
array(2) { ["id"]=> string(11) "56827075005" ["name"]=> string(31) "The College of
William and Mary" } ["year"]=> array(2) { ["id"]=> string(15) "142963519060927"
["name"]=> string(4) "2010" } ["type"]=> string(7) "College" } } ["gender"]=> string(4)
"male" ["email"]=> string(22) "rsmithson505@gmail.com" ["timezone"]=> int(-7)
["locale"]=> string(5) "en_US" ["updated_time"]=> string(24) "2011-12-31T22:29:34+0000" }
所以我可以解决这个问题。但是,我想知道为什么在第二种情况下我没有得到任何错误。
答案 0 :(得分:1)
只要帐户真正经过验证,verified
始终为true
,您就可以随时使用
$verified = !empty($fbme['verified']);