开发者

Facebook App : Problem with storing user info

开发者 https://www.devze.com 2022-12-24 08:06 出处:网络
I want to store basic user info like name and proxied email into my MySQL database. Here\'s my code $facebook = new Facebook($appapikey, $appsecret);

I want to store basic user info like name and proxied email into my MySQL database. Here's my code

$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_la开发者_JS百科stname);
$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>";

Here's the output I get

FQL Result:

FQL Result:

FQL Result:

What am I doing wrong?


From my investigation, here is what I think might be your problem.

In Facebook API uid is int and not a string so your FQL should be specifying a uid of int (but you applied it as a string).

Change

$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'";

To

$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";

I hope $user returns the uid.


Observation update

Also, calling fql_query returns an array of data, so (just in case) why don't you try (not really sure if I'm correct in 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>";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号