2011-03-18 88 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