简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM