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.
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
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.
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.
精彩评论