Foo.Blarg

Pappy’s Ramblings

Get a Facebook Application ID in JavaScript

Posted by pappy74 on February 27, 2009

I needed to get my facebook application’s ID in my Javascript code.  I didn’t see a public API way of doing this or other posts online, so here’s a little hack to get at it:

function getApplicationId() {
try {
some_nonexistent_function();
} catch(e) {
var match = e.message.match(/^a(\d+)_/);
return match[1];
}
}

It takes advantage of the fact that the exception message contains the ID.  Nothing fancy, but I liked it :)

Please let me know if there’s a better way!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.