-1

I am trying to get the lastname of my profile using restfb.But but each time the username is returned as null.I already have the acess token and permissions.I guess t some problem with the JSon object passing.how can i pass the json objects to a javabean and later retrieve it?

sandeepsharat
  • 97
  • 1
  • 3
  • 10

3 Answers3

3

This happens when the access token you provided doesn't have the correct permissions to access the data. Best way to check this is by using the facebook graph API interface; noting the version. https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me&version=v2.4

FacebookClient fbClient = new DefaultFacebookClient(accessToken, Version.VERSION_2_4);
User me = fbClient.fetchObject("me", User.class, Parameter.with("fields", "email,first_name,last_name,gender"));

Note: Your FB.login function must contain the correct scope for fields you want to access.

FB.login(function(response) {

           ...

        }, {scope: 'email'});
Ithar
  • 4,865
  • 4
  • 39
  • 40
0

Here is the code snippet

FacebookClient facebookClient = new DefaultFacebookClient("register a facebook application with required permissions, get that application token and paste here");

User user = facebookClient.fetchObject("me", User.class);

Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);

for(User friend:myFriends.getData())
{
    Connection<Page> myMovies = facebookClient.fetchConnection(friend.getId() + "/movies", Page.class);

    content = content + "Name: " + friend.getName();
    for(Page page:myMovies.getData())
    {
        content = content  + "\n" + "Movies: " + page.getName() + "\n";
    }
}

In this example your application needs "friends_likes" permission.

Hope this helps.

Swamy
  • 771
  • 1
  • 8
  • 24
0

This works for me:

FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
User user = facebookClient.fetchObject("me", User.class);
out.println("Last name: " + user.getLastName());
AnAmuser
  • 1,885
  • 5
  • 26
  • 42
  • Yeah this works if the user is me!.....but what if i want to grab the details of users who are in the friend's list, like for example the location.I guess we have to change the access levels.Im currently stuck at changing the access tokens.Although ive changed that once,I wonder if that itself is the problem or something else.How is it that we change the permissions of access tokens?.... – sandeepsharat Jan 20 '12 at 12:20
  • that's a different question than you originally asked. It's not fair to ask question after question after question in one question. – DMCS Jan 20 '12 at 14:50