如何获得用户的“验证” PHP的状态 [英] How to get user's "verified" status with PHP

查看:147
本文介绍了如何获得用户的“验证” PHP的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个Facebook Connect登录,我用它来获取有关我的用户的一些数据。有一件事我想知道的是用户是否已被Facebook验证。我在文档中看到这个只是已验证的值。当用户授权我的应用程序时,我要求一些基本的访问参数,所以我认为我应该可以访问它。但是,当我尝试返回值时,我只需要一个null。

I have a Facebook Connect login at my website and I use it to get some data about my users. One thing I want to know is whether the user has been verified by Facebook. I see this in the documentation as simply the "verified" value. I've ask for some basic access params when the user authorizes my app so I think I should be able to access it. But when I try to return the value I just get a null.

我的代码是这样的:

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给了我以下内容。我在那里看到我想我必须弄清楚如何提取它。 (不要担心,这是一个测试用户,我已经更改了一些数据,所以我没有在这里公开任何个人信息)

Okay, vardump gives me the following. I see it in there. I guess I have to figure out how to extract it now. (Don't worry, this is a test user and I've changed some of the data so I'm not exposing any personal info here)

用户#1已返回验证值):

User #1 (Has a verified value returned):

{ ["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 :(完全没有返回,甚至没有错误)

User #2: (Nothing returned at all. Not even a false)

{ ["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" } 

所以我可以与此一起工作但是,我想知道为什么在第二种情况下我不会得到一个错误。

So I can work with this. However, I'm wondering why I don't get even a false in the second scenario.

推荐答案

只要验证将始终为 true 当账户真实验证后,您可以随着

As long as verified will be always true when account is really verified - you can just go with

$verified = !empty($fbme['verified']);

这篇关于如何获得用户的“验证” PHP的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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