What is "Authenticating as an Application"?

Have you ever tried to invoke the Old REST API method "admin.getAllocation"?

If you had tried to invoke by using codes that are written for invoking other method like "friends.get" (i.e. get the user session and redirecting the user to Facebook's login page if necessary and then invoke the method), you probably had ended up with an error 15 "The method you are calling must be called with an app secret signed session".

To invoke this kind of administrative method, you have to authenticate as an application first. So, what is "Authenticating as an Application"?

This is how Facebook explained about "Authenticating as an Application":

You can construct an OAuth access token associated with your application via the OAuth Client Credentials Flow. OAuth access tokens have no active user session, but allow you to make administrative calls that do not require an active user (for example, retrieving analytics data).
http://developers.facebook.com/docs/authentication/

 

How to authenticate as an Application

Facebook has told us that we can obtained an access token for our application with

&curl -F grant_type=client_credentials \
      -F client_id=your_app_id \
      -F client_secret=your_app_secret \
      https://graph.facebook.com/oauth/access_tokennbsp;

The above code is what you have to do by using curl. And to do this in php, it will be something like:

  $args = array('grant_type' => 'client_credentials', 
                'client_id' => $appID, 
                'client_secret' =>  $appSecret);

$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $returnValue = curl_exec($ch);
curl_close($ch);

 

How to Invoke admin.getAllocation

By using the application access token extract above, you can now call admin.getAllocation by using code like:

 $old_rest_call_param = array('method' => 'admin.getAllocation', 
                              'access_token' => $appAccessToken,
                              'integration_point_name'=> 'requests_per_day' );
 $allocation = $facebook->api($old_rest_call_param);

 

Cheers!