Facebook Graph API, Age, Country Restrictions

July 30th, 2011 by Eric Cope

I contract to a social media management company who was having intermittent access problems to Facebook’s graph API. A few of their clients could not get their data into this company’s software that I was maintaining for them. Instead of the API returning valid JSON with the page’s public data, it was returning “false”. There was no error code, no error description, not even a fail whale.

After some searching, I was able to determine that if there are any restrictions placed on the page, like age or country, no public data is returned to a graph API call unless you supply your access_token. By adding the access token to the URI, all the expected data appeared and the mystery was solved.

 

Facebook Authentication Gotcha

July 30th, 2011 by Eric Cope

I am working on a project right now that allows the user to log into facebook and grant access to a page or theirs. The documentation says to use this type of call:

https://www.facebook.com/dialog/oauth?
     client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages&
     response_type=token

The problem for me was that a response_type of token redirects the browser with a URI of :

https://domain.com/#access_token=<a_valid_token>

That is not a valid GET variable, therefore requiring you to either parse the URI yourself or not use the Facebook PHP SDK. Since I’m too lazy to not use the SDK, I changed the response_type to “code”. This changed the redirect URI to:

https://domain.com/?code=<some_code>

This valid GET variable, code, is something the PHP SDK will use to obtain the access token to get access to a user’s pages. The PHP SDK sticks it in a cookie temporarily while you fetch page information and each page’s access token. Now, we are ready to go!