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
