我想将名称和代理电子邮件等基本用户信息存储到我的MySQL数据库中。 这是我的代码
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login($required_permissions = 'publish_stream','status_update','email');
$con = mysql_connect("xxxx","xxxxx","xxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxx_userdb", $con);
//Uptil Here it is working fine...No problem with db connection
$fql_firstname = "select first_name from user where uid = '$user'";
$fql_lastname = "select last_name from user where uid = '$user'";
$fql_email = "select proxied_email from user where uid = '$user'";
$fql_fname_result = $facebook->api_client->fql_query($fql_firstname);
$fql_lname_result = $facebook->api_client->fql_query($fql_lastname);
$fql_email_result = $facebook->api_client->fql_query($fql_email);
echo "<pre>FQL Result:" . print_r($fql_fname_result,true) . "</pre>";
echo "<pre>FQL Result:" . print_r($fql_lname_result,true) . "</pre>";
echo "<pre>FQL Result:" . print_r($fql_email_result,true) . "</pre>";
这是我得到的输出
FQL Result:
FQL Result:
FQL Result:
我做错了什么?
答案 0 :(得分:1)
从我的调查来看,这就是我认为可能是你的问题。
在Facebook API中uid
是int
而不是一个字符串,所以你的FQL应该指定一个int的uid(但你把它作为一个字符串应用)。
更改
$fql_firstname = "select first_name from user where uid = '$user'";
$fql_lastname = "select last_name from user where uid = '$user'";
$fql_email = "select proxied_email from user where uid = '$user'";
到
$fql_firstname = "select first_name from user where uid = $user";
$fql_lastname = "select last_name from user where uid = $user";
$fql_email = "select proxied_email from user where uid = $user";
我希望$user
返回uid
。
观察更新
此外,调用fql_query
会返回一个数据数组,因此(以防万一)为什么不尝试(不确定我在PHP中是否正确)
echo "<pre>FQL Result:" . print_r($fql_fname_result[0],true) . "</pre>";
echo "<pre>FQL Result:" . print_r($fql_lname_result[0],true) . "</pre>";
echo "<pre>FQL Result:" . print_r($fql_email_result[0],true) . "</pre>";