2010-03-23 100 views
0

我想將姓名和代理電子郵件等基本用戶信息存儲到我的MySQL數據庫中。 這裏是我的代碼Facebook應用程序:存儲用戶信息的問題

$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

您是否在傳遞您的API密鑰和API密鑰? –

+0

不。我該怎麼做? – Bruce

+0

那你在這裏通過什麼? '$ facebook = new Facebook($ appapikey,$ appsecret);' –

回答

1

從我的調查,這裏是我認爲可能是你的問題。

在Facebook的API uidint一個字符串,因此您的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>"; 
+0

是的$用戶返回的uid ....我也曾想過關於這個......但不幸的是這並沒有幫助.. – Bruce

+0

觀察更新沒有幫助 – Bruce

+1

然後我都沒有選擇。你的代碼在所有方面都看起來正確。抱歉! –

相關問題