Posts tagged ‘Graph API’

Set age restrictions on Facebook apps with the Graph API

This one drove me nuts. Facebook allows developers to restrict applications based on a user’s age and location. This was a pretty important requirement for a recent alcohol brand application we were developing. The api method is called admin.setRestrictionInfo. It makes what would otherwise be a tedious process very simple. No ‘enter your birthdate’ screens, no worrying about posts created by the application soliciting underage users. The method even takes a special parameter called ‘type’ that can be set to ‘alcohol’ (currently the only option for this parameter) which blocks users based on their local drinking age.

Sounds perfect. Until you try implementing it.

The abysmal Facebook documentation provides no examples of how to make this call. In scouring the forums, I discovered that the method only needs to be called once, and this particular application made no use of server-side SDKs, so there wasn’t a convenient way to make the call. I started making calls to the API via simple browser get requests, knowing that the response would be ‘true’ if the call was successful (that, believe it or not, was actually specified in the documentation). I kept getting a variety of error responses. The structure of the request is:

1
https://api.facebook.com/method/admin.setRestrictionInfo?access_token=[YOUR_ACCESS_TOKEN]&format=json&restriction_str={%22type%22:%22alcohol%22}

I was getting the access_token from the “Access Token” string found on the application page in the developer dashboard. But for whatever reason, this method requires you to pass your application id pipe-delimited with your application secret. This is the url structure that ultimately returned ‘true’ when entered into the browser.

1
https://api.facebook.com/method/admin.setRestrictionInfo?access_token=[APP_ID]|[APP_SECRET]&format=json&restriction_str={%22type%22:%22alcohol%22}

A very useful method with absolutely useless documentation. Hope this helps save someone else as much time as I wasted figuring this out…