Skip navigation

I wanted to post custom comments to my Facebook page using Facebook’s dialog. You need the Page’s UID to be able to post to it, and there’s no way in the Open Graph protocol to get the ID of a given URL. Here’s how you do it using the Javascript SDK and FQL:

function facebookGetIdForUrl(url, callback) {
    //see http://developers.facebook.com/docs/reference/fql/object_url/
    FB.api(
          {
            method: 'fql.query',
            query: "SELECT id FROM object_url WHERE url = '" + url + "'"
          },
          function(response) {
            callback(response[0].id);
          }
        );
}

facebookGetIdForUrl("http://facebook.com",
     function (id) {

        alert("Facebook ID = " + id);

    });

 

Leave a Reply