user1117313
user1117313

Reputation: 1985

How to get user location in Facebook API v2.0?

I can get the basic information about user with following:

FB.api('/me', function(response) {
    console.log(location);
});

However I want to get the location of the user. How can I do that? I have tried to use /user method,

FB.api('/user', function(response) {
    console.log(response);
});

But I get following error

(#803) Cannot query users by their username (user)

I will appreciate any help regarding this.

Upvotes: 0

Views: 472

Answers (1)

Tobi
Tobi

Reputation: 31479

There's no /user endpoint. To be able to query for location, you need to request the user_location permission, see https://developers.facebook.com/docs/facebook-login/permissions/v2.0#reference-extended-profile

A sample request would be

FB.api('/me?fields=id,location', function(response) {
    console.log(response);
});

Upvotes: 1

Related Questions