Reputation: 91
does Facebook api provides user's current location(latitude and longitude) when user logged in ? If yes, then how do I get it ? https://graph.facebook.com/me/ provides only user related data, but not the current location. Please help me to get this.
Upvotes: 0
Views: 9406
Reputation: 1474
If you want to find Find user's location(latitude and longitude) on base its profile details when user logged in, through Facebook api? Then Follow this:
Download https://github.com/facebook/facebook-php-sdk and copy all files from src and put in your project folder and rename it to php-sdk
require_once('php-sdk/facebook.php');
$config = array( 'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_SECRET_KEY',
'allowSignedRequest' => false // optional but should be set to false for non-canvas apps );
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$user_profile = $facebook->api('/me','GET');
$query = 'SELECT current_location FROM user WHERE uid = me()';
$response = $facebook->api(array('method' => 'fql.query', 'query' => $query));
print_r($response);
OutPut:
Array
(
[0] => Array
(
[current_location] => Array
(
[city] => Test
[state] => Test
[country] => Test
[zip] =>
[latitude] => 53.0833
[longitude] => 92.6667
[id] => 4555555878787887
[name] => Test
)
)
)
Upvotes: 0
Reputation: 11
Yes, it is possible with facebook FQL query. Please refer below link https://developers.facebook.com/docs/reference/fql/standard_user_info/
Upvotes: 0
Reputation: 91
After going through https://developers.facebook.com/docs/reference/fql/user facebook document,I got the current location with latitude and longitude. To get this we need to fire a query which will select current location from user table with user's access token.
FQL(Facebook Query Language) :
https://graph.facebook.com/fql?q=SELECT current_location FROM user WHERE uid=me()& access_token=xxxxx
Response:
{
"data": [
{
"current_location": {
"city": <city name>,
"state": <state name>,
"country": <country name >,
"zip": <zip code>,
"latitude": <latitude>,
"longitude": <longitude>,
"id": <location id>,
"name": <address>
}
}
]
}
Upvotes: 3