Monday, November 10, 2014

Friend list interface in Facebook SDK after API Version v2.0

[GET /v2.2/me HTTP/1.1]
A user represents a person on Facebook. The /{user-id} node returns a single user.
1. Go to https://developers.facebook.com/docs/graph-api/reference/v2.2/user
2. Click "Graph Explorer" -> "Get Access Token" -> "User Data Permissions" -> Select "user_about_me" -> Click "Get Access Token", you will see a access token look like "CAACEdEose ... ccKEs" show in the field, then click Submit.
3. You will see a JSON string which is an array of Friendlist objects, Ex:
{
    "id": "1234123412341234",
    "bio": "I love music!",
    "first_name": "bear",
    "gender": "male",
    "last_name": "lin",
    "link": "https://www.facebook.com/app_scoped_user_id/1234123412341234/",
    "locale": "zh_TW",
    "name": "bear lin",
    "timezone": 8,
    "updated_time": "2013-11-17T09:22:13+0000",
    "verified": true
}
4. The more Access token you select, the more information will return.


[GET /v2.2/me/friendlists HTTP/1.1]
A person's 'friend lists' - these are groupings of friends such as "Acquaintances" or "Close Friends", or any others that may have been created
1. Go to https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friendlists
2. Click "Graph Explorer" -> "Get Access Token" -> "Extended Permissions" -> Select "read_friendlists" -> Click "Get Access Token", you will see a access token look like "CAACEdEose ... ccKEs" show in the field, then click Submit.
3. You will see a JSON string which is an array of Friendlist objects, Ex:
{
    "data": [
        {
            "id": "4777092484211",
            "name": "Artists",
            "list_type": "user_created"
        },
        {
            "id": "4777064723517",
            "name": "Musicians",
            "list_type": "user_created"
        }
    ],
    "paging": {
        "next": "https://graph.facebook.com/v2.2/1234123412341234/friendlists?limit=5000&offset=5000&__after_id=enc_AeyE7DuzMXSU9JFIGYuR1XfRcZT-U6YI205muBRRkOIAIAk_UhLZ3kMtWkS67_mgwuE"
    }
}

[GET /v2.2/{friendlist-id} HTTP/1.1]
A friend list - an object which refers to a grouping of friends created by someone or generated automatically for someone (such as the "Close Friends" or "Acquaintances" lists)
1. Go to https://developers.facebook.com/docs/graph-api/reference/v2.2/friendlist
2. In the "Graph Explorer" you should replace "{friendlist-id}" with a valid Id(ex: 4777092484211, you can get it from /v2.2/me/friendlists).
3. After submit, Ex:
{
    "id": "4777092484211",
    "name": "Artists",
    "list_type": "user_created"
}
NameDescriptionType
idThe friend list IDstring
nameThe name of the friend liststring
list_typeThe type of the friend listenum{close_friends, acquaintances, restricted, user_created, education, work, current_city, family}

[GET /v2.2/me/friends HTTP/1.1]
A person's friends.
"Friend list now only returns friends who also use your app".
Read below articles fist:
http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-u
https://developers.facebook.com/docs/apps/changelog [Read API Version v2.0 changelog]

1. Go to https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friends
2. In the "Graph Explorer":
Permissions
  • A user access token with user_friends permission is required to view the current person's friends.
  • This will only return any friends who have used (via Facebook Login) the app making the request.
  • If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.
3. After submit: Ex:
{
    "data": [
        {
            "name": "Eric",
            "id": "33333333333333"
        },
        {
            "name": "Lee",
            "id": "111111111111"
        }
    ],
    "paging": {
        "next": "https://graph.facebook.com/v2.2/1234123412341234/friends?limit=25&offset=25&__after_id=enc_AexidG6KKymgeEvLC38u6ERUDQud__sm2tYQkoPMs2ba6l8E17X73s-pSYx5y5hnuDdwFpyt23dt_Gi3GWiZ1raR"
    },
    "summary": {
        "total_count": 307
    }
}
4. You can also using Postman:
GET /v2.2/1234123412341234/friends?access_token=CAACEdEose0cBAIBIg6ZA9P9YNQQxLpmzT4VSBj2dYClv7vIM7aeXNoHpRTq27yGPh14szRVC2VVU6727V66BItbgUuco1tHVo6ZAwr2LhLlZCu3KxuHSuW6ZASBWm9T44RWWnHCbvFELTSJkveqArEAVEdPwkjHIyDFiAQJX6na9uESefCVfX0e4fUNvKjAkvK7b7BSKkhkCEKulWhPO HTTP/1.1
Host: graph.facebook.com


After API Version v2.0, "/me/friends" no longer return full friends list, it only returns the user's friends who are also using your app, please read: http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-u
------------------------------------------------------------------------------------------------------------------------------
In v2.0 of the Graph API, calling /me/friends returns the person's friends who also use the app.
In addition, in v2.0, you must request the user_friends permission from each user. user_friendsis no longer included by default in every login. Each user must grant the user_friends permission in order to appear in the response to /me/friends. See the Facebook upgrade guide  for more detailed information, or review the summary below.
If you want to access a list of non-app-using friends, there are two options:
  1. If you want to let your people tag their friends  in stories that they publish to Facebook using your App, you can use the /me/taggable_friends API. Use of this endpoint requires review by Facebook  and should only be used for the case where you're rendering a list of friends in order to let the user tag them in a post.
  2. If your App is a Game AND your Game supports Facebook Canvas , you can use the /me/invitable_friends endpoint in order to render a custom invite dialog , then pass the tokens returned by this API to the standard Requests Dialog. 
In other cases, apps are no longer able to retrieve the full list of a user's friends (only those friends who have specifically authorized your app using the user_friends permission). This has been confirmed by Facebook as 'by design'. 
For apps wanting allow people to invite friends to use an app, you can still use the Send Dialog on Web or the new Message Dialog on iOS  and Android .
UPDATE: Facebook have published an FAQ on these changes here:https://developers.facebook.com/docs/apps/faq  which explain all the options available to developers in order to invite friends etc.
------------------------------------------------------------------------------------------------------------------------------
References:
https://developers.facebook.com/docs/apps/faq
https://developers.facebook.com/docs/apps/changelog [Read API Version v2.0 changelog]
https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

[TODO]
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/taggable_friends
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/invitable_friends

No comments:

Post a Comment