2010-04-08 40 views
0

我想在Facebook上獲取用戶名。爲此,我嘗試使用FQL查詢。代碼是,php中的fql查詢問題

$result = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid='$user_id'); 

但是,這有一些問題。我猜查詢沒有得到執行,或者它返回空值。我也嘗試使用users.getInfo如下,

$result = $facebook->api_client->users_getInfo($user_id,'name'); 

但是,同樣的問題。

我試圖顯示陣列,

echo $result['name]; 

所以,我想無論是作爲代碼,

if(!$facebook->api_client->fql_query("SELECT name FROM user WHERE uid='$user_id')) { 
    echo "Error."; 
} 

我已經包含在我的PHP文件都facebook.php和facebookapi_php5_restlib.php 。我哪裏錯了?

回答

0

現在我可以修復這個問題.. 打開和修改文件facebookapi_php5_restlib.php和像

這個

public function post_request($method, $params, $server_addr) { 
    list($get, $post) = $this->finalize_params($method, $params); 
    $post_string = $this->create_url_string($post); 
    $get_string = $this->create_url_string($get); 
    $url_with_get = $server_addr . '?' . $get_string; 
    if ($this->use_curl_if_available && function_exists('curl_init')) 
    { 
     $useragent = 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion(); 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url_with_get); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3600); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 3600); 
     $result = $this->curl_exec($ch); 
     curl_close($ch); 
    } else { 

    $content_type = 'application/x-www-form-urlencoded'; 
     $content = $post_string; 
     $result = $this->run_http_post_transaction($content_type,$content, $url_with_get); 
    } 
    return $result; 
    } 

變化超時