Sreeraj
Sreeraj

Reputation: 2720

How do i get user country Name using facebook api connect?

I am developing a facebook application. I have to know the country of the logged in user using the graph API.

Upvotes: 2

Views: 5494

Answers (3)

James P.
James P.

Reputation: 19617

If you save the profile data to a MySQL table you can do something like this to extract the name of the country:

SELECT
    SUBSTRING_INDEX( users_facebook.hometown,  ',' , -1 ) ,
    hometown,
    ABS( LENGTH( REPLACE( hometown,  ",",  "" ) ) - LENGTH( hometown ) ) AS num_commas
FROM
    users_facebook
WHERE
    ABS( LENGTH( REPLACE( hometown,  ",",  "" ) ) - LENGTH( hometown ) ) <> 0

Something similar should be possible in PHP (split, last element...) when you're acquiring the data.

Upvotes: 0

Elad Lachmi
Elad Lachmi

Reputation: 10581

You can query the user table through FQL. The column you are looking for is current_location.

http://developers.facebook.com/docs/reference/fql/user/

You can use FQL through the graph api:

https://api.facebook.com/method/fql.query?query=QUERY

Upvotes: 2

MartinHN
MartinHN

Reputation: 19812

First of all, during Authentication you might need to request the user_location permission. I don't know if this is required to get information from the logged in user. Try.

After you have the required permission (if needed), make a request to the Graph API using this URL: https://graph.facebook.com/me?access_token=YOUR_TOKEN.

You can try to use the link Facebook provides in their documentation. Make sure you're signed in to your Facebook account in the current browser, and click here to see your own information.

Upvotes: 1

Related Questions