1

I'm trying to get the user location from Facebook.

In the Graph API › User page, says:

location : A JSON object containing name and id

I need the location name, and I cannot get it. So far I've done:

$loc = $facebook->api('/me', array('fields' => 'location'));

But I don't get it and don't know what else to do ..

Thanks a ton!

3

2 Answers 2

0

You'll need to request the "user_location" privilege.

If you're using the Login Button, add it to the perms parameter.

<fb:login-button perms="user_location"></fb:login-button>

If you're using the Javascript API, add it to the options parameter:

FB.login(function(response) {
    if (response.session) {
        // do stuff
    }
}, { perms:"user_location" });

You may also want to try this to see what data is available.

$response = $facebook->api('/me');
var_dump($response);
Sign up to request clarification or add additional context in comments.

2 Comments

I had the perms already in the Login Button my problem is the location name. Printing /me, does not show the location. My code is just printing the location id. Thanks a lot
With the proper permissions, I get this when I run your code snippet: array ('location' => array('id' => 'location uid', 'name' => 'location name'), 'id' => 'user uid'). The only thing I can think is that you don't have a location set in Facebook.
0

Make sure you have right privileges, If not request them first.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.