Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created May 18, 2012 11:24
Show Gist options
  • Save kopiro/2724766 to your computer and use it in GitHub Desktop.
Save kopiro/2724766 to your computer and use it in GitHub Desktop.
Get ID of Facebook by URL
getFBId = function(t)
{
if (!window.jQuery) return;
var span = $('#fbid');
var url = t.value;
span.text('Calcolo..');
var id = url.match(/facebook\.com\/profile\.php\?id\=([0-9]*)/);
if (id)
{
span.text(id[1]);
}
var usr = url.match(/facebook\.com\/([a-zA-Z0-9._-]*)/);
if (!usr)
{
span.text('Errore!');
return;
}
$.getJSON('http://graph.facebook.com/'+usr[1], function(r)
{
if (!r)
{
span.text('Errore!');
return;
}
span.text(r.id);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment