Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I manage many pages as one admin user without exceeding api quota?

My client company manages Facebook Pages for several thousand small businesses. We've built a Facebook App that for our client to simplify the process and allow them to quickly make changes to many/all the pages in one go.

For whatever set of business reasons our client company has just ONE of their employees added as an administrator (along with the small business owner) for each of these pages. This user account has added our App and we are grabbing page tokens and using those page tokens to manage the page (change the contact info, add a tab, fetch wall posts). We're coming up against some really harsh api request limits. Right now we can only add about 3 new Facebook Pages a minute (which I think requires maybe 6-10 api calls when its all said and done).

I've seen people estimate that a you're allowed about 600requests/600seconds for an access token but I thought that since we were doing most of the work with page tokens our actions wouldn't be counted towards a single api limit.

Does anyone know for sure if the api limits are based on individual tokens even if they technically belong to the same user? Is there any way I can get around this limit considering that I can't really add more admins to these pages?

like image 272
Tony Bathgate Avatar asked Mar 07 '13 17:03

Tony Bathgate


2 Answers

Actuelly its quite simple, you just need to ask for an access token for the PAGE, not the user.

    $mQuery=array('access_token'=> 'SELECT access_token FROM page WHERE page_id = 'page_id,    
                  'album_id'=> 'SELECT object_id FROM album WHERE owner = '.page_id.' AND name = "Timeline Photos"');
    $multiQueryResult = $facebook->api(array('method'=>'fql.multiquery', 'queries'=>$mQuery));

The first line will get you the access token of that user, and the second its just an example for using multiquery, and reduce your calls.

You can use a max of 50 queries in a multiquery

And if you want to do several things with your page, you can use batch request. This is an example for posting a status, you can add more, until 50 batch request in the same call.

$v['body']['message']=htmlspecialchars_decode($v['message'], ENT_QUOTES);
$v['body']['scheduled_publish_time']=strtotime($v['scheduled_publish_time']);
$v['body']['published']='false';
$v['body']=http_build_query($v['body']);
$batch[]=$v;

try {
    $batchresult = $facebook->api("/?batch=".urlencode(json_encode($batch)), 'POST', array('access_token'=>$access_token));
} catch (FacebookApiException $e) {
    echo $e->getMessage(); 
}
echo $batchresult;

Hope this helps.

like image 123
Julio Popócatl Avatar answered Oct 03 '22 12:10

Julio Popócatl


As @Julio Popócatl refered, using a Page Access Token (generated from a long-lived user token) could be a good choice.

These Page Access Tokens once generated correctly, they will never expire, so it is at least one less query you need to run.

The API requests limit is applied to every request, being from user, page, app, whatever. They are always asking something to Facebook schema, whatever the source of the request is.

Using batch requests is a good idea too, as it would be fetching multiple data with one (or less) requests than making each request individually.

like image 30
Ivo Pereira Avatar answered Oct 03 '22 11:10

Ivo Pereira