2012-03-23 75 views
0

我正在開發具有現在完成了我的第一個Facebook,在我的應用程序香港專業教育學院使用file_get_contents功能來檢索圖形API內容:替代從圖形API檢索信息

$userName = json_decode(file_get_contents('http://graph.facebook.com/' . $userId)) -> name; 

但問題是,我現在使用的主機不允許使用file_get_contents函數。

  • 所以我想知道還有什麼其他的替代方法可以用來檢索 來自graph api的信息嗎?
  • 從谷歌搜索我發現了Facebook的PHP SDK提供了不同的 替代品。 Ive include ('src/facebook.php');包含在 我的代碼,但我不知道如何使用,或者有沒有辦法我可以 用戶sdk來克服我的問題?

請幫忙。

三江源。

+0

最好嘗試SDK詳細的教程。在這裏可以選擇'fopen','fsockopen'和'CURL' – safarov 2012-03-23 22:37:34

+0

Facebook開發者PHP SDK文檔是一個很好的起點... https://developers.facebook.com/docs/reference/php/ – keithhatfield 2012-03-23 22:46:38

回答

2

最好的解決方案是使用Facebook PHP SDK。

的代碼將類似於:

$app_id  = "Your App ID/API Key goes here"; 
$app_secret = "Your App secret goes here"; 
$site_url  = "Your Site URL goes here"; 

include_once "src/facebook.php"; 

$facebook = new Facebook(array(
    'appId'  => $app_id, 
    'secret' => $app_secret, 
    )); 

$user = $facebook->getUser(); 

if($user){ 
    try{ 
     $user_profile = $facebook->api('/me'); 
    }catch(FacebookApiException $e){ 
     $user = NULL; 
    } 
} 

if($user){ 
    $logoutUrl = $facebook->getLogoutUrl(); 
}else{ 
    $loginUrl = $facebook->getLoginUrl(array(
     'scope'  => 'read_stream publish_stream email', 
     'redirect_uri' => $site_url, 
     )); 
} 

你可以找到http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/