Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created August 29, 2010 03:04
Show Gist options
  • Save cheeaun/555902 to your computer and use it in GitHub Desktop.
Save cheeaun/555902 to your computer and use it in GitHub Desktop.
Get your Facebook friends' current location
<!DOCTYPE html>
<title>FB Friend Locationer</title>
<style>
* {font-family: sans-serif;}
table th, table td{border: 1px solid #ccc; padding: 0 1em;}
</style>
<table id="loc">
<thead>
<tr>
<th>Name</th><th>Current location</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
/*
Get your access_token from http://developers.facebook.com/docs/api
If you are a web developer, you'll know how to do this. I'm lazy to explain here.
*/
var access_token = 'INSERT BACON HERE';
var tbody = $('#loc tbody');
$.ajax({
url: 'https://graph.facebook.com/me/friends',
data: {
access_token: access_token
},
dataType: 'jsonp',
success: function(json){
var data = json.data;
for (var i=0, l=data.length; i<l; i++){
var id = data[i].id;
$.ajax({
url: 'https://graph.facebook.com/' + id,
data: {
access_token: access_token
},
dataType: 'jsonp',
success: function(json1){
var location = json1.location;
if (typeof location == 'undefined') return;
location = location.name;
if (!location) return;
var name = json1.name;
tbody.append('<tr><td>' + name + '</td><td>' + location + '</td></tr>');
}
});
}
}
});
</script>
@KingKeada
Copy link

too bad, is there an other option to extract that from a friends profile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment