开发者

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

开发者 https://www.devze.com 2023-03-13 22:06 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消