Facebook emails always return null through FQL and RestFB

柔情痞子 提交于 2019-12-05 06:15:59

to access user's private informations like email,posts etc you should have the permission to access those details .for more details visit https://developers.facebook.com/docs/reference/api/permissions/

Youdhveer

If you are using restfb (Facebook graph API and old REST API client wriiten in Java), and you want to access all friend list after Oauth authentication, you can use following method to access the friends list and facebook id's,

public List<ArrayList> findFacebookFriendsUsingRest(String facebookAccessToken){

    List<ArrayList> myFacebookFriendList= new ArrayList();
    final FacebookClient facebookClient;
    facebookClient = new DefaultFacebookClient(facebookAccessToken);
    User user = facebookClient.fetchObject("me", User.class);
    String userName = user.getFirstName();

    if (userName == null){
        userName = user.getLastName();
    }

    String userEmail = user.getEmail();
    com.restfb.Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);

    System.out.println("Count of my friends: " + myFriends.getData().size());

    for(User friend: myFriends.getData()){
        System.out.println("Friends id and name: "+friend.getId()+" , "+friend.getName());      
        myFacebookFriendList.add(friend.getName());
    }

    System.out.println("All Friends : "+myFacebookFriendList);
}

Facebook does not provide user, unless the user authorizes your application to access it. It's on account of security and user privacy, imagine how terrible it would be if everybody could have at her disposal all FB user's email addresses.

Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class ,Parameter.with("fields", "id, name, picture, email"));

You can specify any of the properties listed under http://developers.facebook.com/docs/reference/api/user

The only thing is that FB does not seam to return the friends email.. I'm using restFb 1.5.3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!