Take the 2-minute tour ×

Specifically, I am working on a class that I can call that would have a method I can pass an id (the ID of a companies page) and would want the number for the like_count returned.

I walked through the steps to get what I thought was a no expire access_token (used the scope=offline_access).

a) I created an API and got the 'APP id' and the 'App Secret'

b) Then I make a request to the URL https to graph.facebook.com/oauth

to get a code using the following (has example data)


This produced a code response {THE_CODE_RESPONSE}

c) Then made a request to https to graph.facebook.com/oauth/

to get an access_token using the following (also example)


I did get an access_token {THE_ACCESS_TOKEN} .

The above looks to work.

What I was trying to do was to get an access token that I can use to make requests to the graph API to get likes


A couple of questions:

1) How to get {ID} for a company? Is the id from a:

SELECT domain_id FROM domain WHERE domain_name='www.facebook.com'

? Or is there another means?

2) Am I on the correct path with https to graph.facebook.com/{ID}/?access_token={THE_ACCESS_TOKEN} ?

In the end what I would like to do is have a means to get the needed detail (is that some ID) to be able to find the like_count given a domain name.

Did I provide enough details or information for my question?

share|improve this question
add comment

2 Answers

Think easy. If you really just want the like_count for

a) a facebook (business) page b) a website

then you don't have to use the any Auth or Apps. Just call the graph api and extract the 'like' (case a) or shares (case b) from the json object!

For example:

a) http://graph.facebook.com/yahoo
b) http://graph.facebook.com/http://www.yahoo.com

If you need the id of a facebook page, just extract the 'id' from the json object. There are afaik no id's for webpages!

Code example:

$url_or_id = implode(",",$permalinks);
$handle = @file_get_contents("https://graph.facebook.com/?ids=".urlencode($url_or_id));
$handle = json_decode($handle, true);

$likes = $handle['likes']; // case a
$shares = $handle['shares']; // case b
$id = $handle['id']; // id of facebook page/account
share|improve this answer
danontheline - - thanks. I suspect this is predicated on the target having a set up based on their domain (may not need to be said). It looks like I fell into a trap that the API ID ... was needed to get access to this information. Thanks for the solution. In my question, where did I go wrong in the request to the ID with the access_token? Was I on the wrong track or should that work? I tried using the Scribe libraries as well and am stuck. I will start with the straightforward path your show. Addition feedback is welcome thanks –  Caffeine Borg Oct 14 '11 at 2:18
add comment

developers.facebook.com -> tools -> Graph API Explorer -> select id checkbox in left bottom corner. I think you might need this value to get likes count.

share|improve this answer
add comment

Your Answer


