I\'m working on application which need birth dates of all friends. Can some body share code how to get birth dates of all friends using graph API. I\'m using following code:
First define your callback, where you'll get friends and birthday info, if authenticated:
Session.StatusCallback statusCallback = new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// Private method, to be defined
makeFriendsRequest();
}
}
};
Then, you can open the session and pass in the necessary, "friends_birthday" permissions request:
Session session = new Session(this);
session.openForRead(new Session.OpenRequest(this)
.setCallback(statusCallback)
.setPermissions(Arrays.asList("friends_birthday")));
Finally, here's the post-authentication method you can use to get friends info, including the birthday:
private void makeFriendsRequest() {
Request myFriendsRequest = Request.newMyFriendsRequest(Session.getActiveSession(),
new Request.GraphUserListCallback() {
@Override
public void onCompleted(List users, Response response) {
if (response.getError() == null) {
// Handle response
}
}
});
// Add birthday to the list of info to get.
Bundle requestParams = myFriendsRequest.getParameters();
requestParams.putString("fields", "name,birthday");
myFriendsRequest.setParameters(requestParams);
myFriendsRequest.executeAsync();
}
Also check out the SessionLoginSample app, bundled with the SDK if you're looking for different ways you can implement Facebook Login.