PHP code example of vlechemin / facebook-batch-api

1. Go to this page and download the library: Download vlechemin/facebook-batch-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vlechemin / facebook-batch-api example snippets


// use the api as usual, please note the &
$me = &$facebook->batchApi('/me');
$picture = &$facebook->batchApi('/me/picture', 'GET', [
    'type' => 'large',
    'return_ssl_resources' => 1,
]);

// execute the batch to fill $me and $picture with the real value
$facebook->processBatch();

// use the results
var_dump($me);
var_dump($picture);

$result1 = &$facebook->batchApi('me/feed', 'POST', [
    'message' => 'Test status update',
    'link' => 'https://developers.facebook.com/',
]);
$result2 = &$facebook->batchApi('me/feed', 'GET', [
    'limit' => 1,
]);
$facebook->processBatch();

$result1 = &$facebook->batchApi('me/friends', 'GET', [
    'limit' => 5,
], [
    'name' => 'get-friends',
]);
$result2 = &$facebook->batchApi('/', 'GET', [
    'ids' => '{result=get-friends:$.data.*.id}',
]);
$facebook->processBatch();

$result1 = &$facebook->batchApi('me/photos', 'POST', [
    'message' => 'My cat photo',
], [
    'attached_files' => $facebook->attachFile('@cat.gif'),
]);
$result2 = &$facebook->batchApi('me/photos', 'POST', [
    'message' => 'My dog photo',
], [
    'attached_files' => $facebook->attachFile('@dog.jpg'),
]);
$facebook->processBatch();