2011-05-24 60 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) 
{ 

}  
相关问题