0

I am having some troubles to get the location data from the end-user Facebook friends list on my Android application.

So far I can successfully open a Facebook Session, store & restore the access token and fetch the user friends list.

As defined in the Android Facebook SDK >3.0, a Facebook user data is strongly-typed in an Object called GraphUser.

To fetch the Friends List, I user Request.newMyFriendsRequest which, upon success, provides me with a list of GraphUsers.

Unfortunately, though I provided the necessary permissions for my endeavor, I fail to retrieve more than the end-user friends names and ID... that's all : each end-user Facebook friend is a GraphUser that contains only their name and their ID.

Here is the list of permissions I use :

"user_status", "read_friendlists", "email", "user_location", "friends_location"

Using the Facebook LoginButton, the SDK tells the end-user that the app does require the aforementioned list of permissions.

Bu when I want to use Graphuser.getLocation, I do get null value. No city, not state, no ZIP code, no nothing.

This is the code snippet to retrieve the end-user data :

public final void setCurrentUser(final Context context) {
    if (this.session != null && this.session.isOpened()) {
        final Request requestCurrentUserProfile = Request.newMeRequest(
                this.session, new Request.GraphUserCallback() {
            public final  void onCompleted(final GraphUser user, final Response response) {
                currentUser = user; // currentUser is defined as a class member
                if (response.getError() != null ) {
                    // TODO
                }
            }
        });
        requestCurrentUserProfile.executeAsync();
    } else
        this.currentUser = null;
}

Placing a break-point here, with the debugger, the GraphUser representation is complete : I have all the data that I need, including the location !

Regarding the end-user Friends list ...

public final void fetchFriendsList() {
    if (this.session != null && this.session.isOpened()) {
        final Request requestUserFriendsList = Request.newMyFriendsRequest(
                this.session, new Request.GraphUserListCallback() {
                    public final void onCompleted(final List<GraphUser> users, final Response response) {
                        if (users != null && users.size() > 0)
                            userFriendsList = new ArrayList<GraphUser>(users);
                    }
                }
        );
        requestUserFriendsList.executeAsync();
    }
}

This is where the users are almost empty : just a name and an ID. That's it, that's all.

Perhas this Request doesn't provide more data ?

If so, which method should I use to fetch the data I need ?

Thanks !

[EDIT]

Looking at my app review status I'm not even suppose to rerieve the Friends List nor the location data of the current end-user ?? !

List of Permission for my App

What is happening here ? I don't get it ... please help !

[EDIT2]

To show you the difference between the end-user GraphUser and the end-user friends list GraphUsers, here is a screenshot of the debugger. Fields have been intentionnaly removed for privacy reasons. Comparison between the end-user and the end-user Facebook friends

Mackovich
  • 2,633
  • 3
  • 25
  • 60
  • Are you using API v1.0 or v2.0? If you created the app after 4/30/2014 you are forced to use v2.0 and in that case friends_location is not available – WizKid May 26 '14 at 16:20
  • According to my app login activity my app was created a bit before : April 28th 2014. But how do I know which Graph API version am I using ? And in any case, is there any way to retrieve the location at all ?? – Mackovich May 26 '14 at 16:25
  • Ok then that is not the problem – WizKid May 26 '14 at 16:28
  • I hope so .. I really need such data or else my app is pretty much useless ! At any rate, I added a screenshot on my OP and hope it will help shed some light on my issue. Thanks ! – Mackovich May 26 '14 at 16:34

1 Answers1

1

You might have to explicitly request those fields in the request parameter when asking friend's data.

Like this,

private void makeMyFriendsRequest(final Session session) {
    Request request = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
        @Override
        public void onCompleted(List<GraphUser> users, Response response) {
            // If the response is successful
            if (session == Session.getActiveSession()) {
                for (GraphUser user : users) {
                    System.out.println(user.getFirstName() + " " + user.getLastName());
                    System.out.println(users.get(i).getId());
                    GraphLocation loc = users.get(i).getLocation();
                    System.out.println(loc != null ? loc.getCity() : "loc not available");
                }
            }
        }
    });

// here add fields explicitly
Bundle bundle = request.getParameters();
bundle.putString("fields", "id,first_name,last_name,birthday,location");
request.executeAsync();

I hope this will help.

PS: I assume that you're requesting your permissions with login button like this,

loginButton.setReadPermissions(Arrays.asList("user_location", "friends_location"));
shaktiman_droid
  • 2,048
  • 1
  • 13
  • 28
  • Thanks for the answer. First, I checked with the debugger the content of users. It's a List made of GraphUser. Checking deeper shows that, as explained in my post, this list of GraphUser contains only the full name and the ID. Here's a screenshot to compare between a friend and the end-user : http://image.noelshack.com/fichiers/2014/22/1401176777-fb-comparaison.png . So your code might produce a NullPointerException on my case. Second, regarding the permission, your are correct: it set those on the LoginButton and my app did ask those permission upon login. – Mackovich May 27 '14 at 07:46
  • 1
    Well did you try the code I posted ? Your screenshot shows the only full name and ID because you're not requesting other parameters in the request. Add bundle params with "fields" key as shown in my example and you'll get more fields – shaktiman_droid May 27 '14 at 17:03
  • No I have not. Sorry ! But where do you send that Bundle ? I don't see how it is "linked" with the Request ... Anyway, after doing some reading ... the GraphAPI v2.0 will completely take over the v1.0 on April 30th 2015. On that day I won't even get the friend list ... – Mackovich May 28 '14 at 13:08
  • Thanks it works now !! But for how long ? There is something I need to know ... by using the Android Facebook SDK am I using the GraphAPI or not ? – Mackovich May 28 '14 at 14:23
  • 1
    @Mackovich You haven't notice that we're getting bundle from Request only. see "request.getParameters()". You're requesting parameters for that request and then you're adding more fields to it. That's how it works. Well April 2015 is almost a year from now. You better worry about that when that happens. I'm sure Facebook will provide exhaustive documentation and samples for a really big change. – shaktiman_droid May 28 '14 at 17:39
  • Well according to : http://www.neontsunami.com/post/getting-facebook-friends-with-the-graph-api-v2-0 the message is pretty clear. And in more details : http://stackoverflow.com/a/23417628/3535408 The situation is dire and we all hope Facebook will change his new policies. I mean, they just can't do that ... how are suppose to send invite to the user friends list to use the app ? It's a basic yet essential and necessary feature ! – Mackovich Jun 02 '14 at 07:24