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

ⅰ亾dé卋堺 提交于 2020-01-02 16:57:09

问题


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


回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6409201/how-do-i-get-user-country-name-using-facebook-api-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!