开发者

Facebook friends birthdays in Android

in Android, what is the easiest way to get ones Friend's birthdays? Or relationship status? Using FQL or by requesting it via the Facebook API开发者_如何学Python SDK for Android?

Thanks.


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

Now if you print the jobject1 you will get the all your friends birthday list..

The response will be in JSON format you have to get the value from it..

authenticatedFacebook is you object for Facebook..

For further clarification you check in this link.....

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

Make sure that you gave permission for accessing friends Birthday date..


what is the easiest way to get ones Friend's birthdays? Or relationship status?

Using FQL we can get birthday and relationship status of a user's friends in one query like this:

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

which can be implemented on Android using the Facebook Android SDK like so:

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())

where FQLRequestListener extends RequestListener.

JSON response will look like this:

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

You need the

friends_birthday

permission


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);
        }
    } 
}

You Need to add Permissions

friends_birthday
friends_location
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜