2011-03-18 91 views

回答

12
Bundle params = new Bundle(); 
params.putString("fields","birthday"); 
JSONObject jObject1 = new JSONObject(authenticatedFacebook.request("me/friends",params));  

现在,如果你打印jobject1你会得到你所有的朋友的生日列表..

的响应将是JSON格式,你必须得到它的价值..

authenticatedFacebook是你对象为Facebook ..

对于在此link检查进一步明确.....

private static final String[] PERMISSIONS = 
    new String[] {"friends_birthday","read_stream", "offline_access"}; 

确保你给访问朋友的生日日期许可..

+0

非常感谢! – user584513 2011-03-18 10:44:49

+0

如果我们需要更多关于我们朋友的信息,该怎么办? 检查它。 http://stackoverflow.com/questions/8560523/getting-friends-information-in-facebook-using-android 2011-12-19 11:25:45

2

是什么让那些朋友的生日最简单的方法?或关系状态?

使用FQL我们可以得到用户的朋友的生日的关系状态在一个这样的查询:

SELECT uid, name, birthday_date, relationship_status 
FROM user 
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) 

可以在Android使用Facebook的Android SDK,像这样实现:

String query = "SELECT uid, name, birthday_date, relationship_status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())" 

Bundle params = new Bundle(); 
params.putString("method", "fql.query"); 
params.putString("query", query); 
mAsyncFacebookRunner.request(null, params, new FQLRequestListener()) 

其中FQLRequestListener扩展了RequestListener。

JSON响应将是这样的:

{ 
"data": [ 
    { 
    "uid": 1234567890, 
    "name": "John Smith", 
    "birthday_date": "06/16", 
    "relationship_status": "Married" 
}, 
{ 
    "uid": etc... 

您需要

friends_birthday 

许可

+0

@RishiVerma感谢您的权利的帮助。 – 2012-12-14 13:37:14

0
try { 

    parameters.putString("format", "json"); 
    parameters.putString(TOKEN, mAccessToken); 

    String url = "https://graph.facebook.com/me/friends?fields=id,name,birthday,location"; 
    String response = Util.openUrl(url, "GET", parameters); 
    JSONObject obj = Util.parseJson(response); 

    Log.i("json Response", obj.toString()); 
    JSONArray array = obj.optJSONArray("data"); 

    if (array != null) { 
     for (int i = 0; i < array.length(); i++) { 
      String name = array.getJSONObject(i).getString("name"); 

      String id = array.getJSONObject(i).getString("id"); 

      Log.i(name,id); 
     } 
    } 
} 

你需要添加权限

friends_birthday 
friends_location 
+0

也检查此链接https://developers.facebook.com/docs/graph-api/reference/user – 2014-04-03 09:41:58