2014-09-29 38 views
-3

我正在開發社交媒體的網絡應用程序我想獲得應用程序的用戶朋友列表和他們的詳細信息我試圖檢索用戶朋友數據使用PHP SDK 4.0,但它給了我一個空數組,然後我嘗試使用json格式獲取數據。這是我的代碼我現在想如何檢索Facebook應用程序的用戶朋友列表與他們的詳細信息使用PHP

<?php 
     $fb_config = array(
      'appId' => 'xxxxxxxxxxxx', 
      'secret' => 'xxxxxxxxxxxxxxxxx', 
      'cookie' => TRUE 
     ); 
     $this->load->library('facebook', $fb_config); 
     $user = $this->facebook->getUser(); 

     if ($user) { 
      try { 
       $data['user_profile'] = $this->facebook->api('/me'); 
      } catch (FacebookApiException $e) { 
       $user = null; 
      } 
     } 

     if ($user) { //ok, the user exist, proceed 
      $access_token = $this->facebook->getAccessToken(); 

      $file = file_get_contents('https://graph.facebook.com/me/friends?access_token=' . $access_token); 


      $jsonFriends = json_decode($file, true); 
      $Friends = $jsonFriends['data']; 
     } 
?> 

我越來越

Fatal error: Using $this when not in object context in M:\xampp\htdocs\fb\demo.php on line 7

這個錯誤,當我運行這段代碼。

+0

這個錯誤是自我解釋 – 2014-09-29 04:22:22

+1

多少錢你知道PHP?你自己寫了這些代碼嗎? – 2014-09-29 04:27:21

+0

我是新來的PHP開發https://www.socketloop.com/tutorials/get-facebook-friends-list-data-with-php-return-json-format – user3021253 2014-09-29 04:54:58

回答

0

您需要更改

$this->load->library('facebook', $fb_config); 

FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET'); 

作爲開始。

該陣列通常是對JavaScript SDK

$fb_config = array(
     'appId' => 'xxxxxxxxxxxx', 
     'secret' => 'xxxxxxxxxxxxxxxxx', 
     'cookie' => TRUE 
    ); 

而且從哪兒弄來的訪問令牌或會話。

你使用JS sdk的另一頁嗎?因爲我找不到「FacebookRedirectLoginHelper」或「FacebookJavaScriptLoginHelper」的實例。

我真的建議你在這裏開始通過該文件會被Facebook:

https://developers.facebook.com/docs/php/gettingstarted/4.0.0

相關問題