2011-05-24 43 views
-1

我的代碼是檢索細節臉書的朋友(名字,姓氏,性別等): -我想用Facebook的帳號

try 
    { 
     params.putString("fields", "first_name"); 
     params.putString("fields", "last_name"); 
     params.putString("fields", "link"); 
     params.putString("fields", "gender"); 
     params.putString("fields", "birthday"); 

     JSONObject json = new JSONObject(facebook.request(Id, params)); 
     JSONArray array = json.getJSONArray("data"); 
     if(array != null) 
     { 
      for(int i=0;i<array.length();i++) 
      { 
       String name = array.getJSONObject(i).getString("name"); 
       String birthday = array.getJSONObject(i).getString("friends_birthday"); 
       String location = array.getJSONObject(i).getString("friends_location"); 
       String web = array.getJSONObject(i).getString("friends_website"); 

       System.out.println(name+"-"+birthday+"-"+location+"-"+web); 
      } 
     } 

    } 
    catch(Exception e) 
    { 

    }  

在哪裏我commtting錯誤。請幫幫我。在此先感謝

+1

您的錯誤?其實:不告訴我們,當你運行你的代碼時會發生什麼;) – 2011-05-24 09:25:45

+0

儘快刪除你最後的評論!該鏈接包含一些您不應該放棄的數據。更好地添加(消毒)結果從得到您的問題 – 2011-05-24 09:37:58

+0

我無法檢索所需的屬性,但這些甚至沒有給出任何錯誤 但也不打印結果在終端 – Gomzy 2011-05-24 09:48:32

回答

0

如果您不告訴我們您的代碼需要做什麼以及出現什麼問題,那麼很難爲您提供幫助。

但是,通過查看您的代碼,我會告訴您確認您正在以正確的方式放置所需的字段。如果參數的工作方式類似於散列表,那麼您將過度檢查關鍵「字段」的值 - 因此,您不會要求first_name,last_name等,而只會要求您過生日。

+0

我試圖檢索名字和姓氏和生日......但在終端中沒有顯示結果,除了包含值爲 – Gomzy 2011-05-24 10:43:29

+0

的所需結果ID的URL是系統。 out.println永遠被調用?正在打印什麼? – pandre 2011-05-24 11:03:53

+0

沒有打印在System.out.println – Gomzy 2011-05-24 11:29:42

1

我們可以得到用戶朋友的詳細信息 Bundle params = new Bundle(); String accessToken = facebook.getAccessToken();

try 
    { 
      params.putString("format", "json"); 
      params.putString("access_token", accessToken); 

      String url = "https://graph.facebook.com/"+Id; 
      String response = Util.openUrl(url, "GET", params); 

      JSONObject json = Util.parseJson(response); 
      String fname = json.getString("first_name"); 
      String lname = json.getString("last_name"); 
      String birthday = json.getString("birthday"); 
      String gender = json.getString("gender"); 
      String location = json.getString("locale"); 
      String web = json.getString("link"); 

} 
catch(Exception e) 
{ 

}  
相關問題