Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For Batch API, you could use the <a href="http://blog.pclabs.com.tr/gokhanozturk/2011/11/17/facebook-batch-requests-php-class/" rel="nofollow">Facebook Batch PHP class</a>.</p> <p><a href="http://snipt.org/qpJp4" rel="nofollow">Here is the code you would use</a>:</p> <pre><code>&lt;?php // Facebook Batch Requests PHP Class // by Gokhan Ozturk &lt;gokhanozturk at gmail dot com&gt; @ Nov 17, 2011 // Original Article: http://blog.pclabs.com.tr/gokhanozturk/2011/11/17/facebook-batch-requests-php-class/ class facebook_batch { protected $requests = array(); protected $responses = null; protected $cur = 1; protected $map = array(); const MAX_NUMBER_OF_REQUESTS = 20; public function add($path, $method = 'GET', $params = array(), $extra = array()) { if(count($this-&gt;requests) &gt; self::MAX_NUMBER_OF_REQUESTS) return false; $path = trim($path, '/ '); $body = http_build_query($params); $body = urldecode($body); if(strtolower($method) == 'get') { if(count($params) &gt; 0) { $path .= "?" . $body; $body = ""; } } $key = $this-&gt;cur++; $this-&gt;requests[$key] = array_merge(array('relative_url' =&gt; $path, 'method' =&gt; $method, 'body' =&gt; $body), $extra); return intval($key); } public function remove($key) { unset($this-&gt;requests[$key]); } public function execute() { global $facebook; $i = 0; foreach($this-&gt;requests as $k =&gt; $r) { $this-&gt;map[$k] = $i++; } $batch = json_encode(array_values($this-&gt;requests)); $params = array('batch' =&gt; $batch); $this-&gt;responses = $facebook-&gt;api('/', 'POST', $params); } public function response($key) { if(! $this-&gt;responses) $this-&gt;execute(); $rkey = $this-&gt;map[intval($key)]; $resp = $this-&gt;responses[intval($rkey)]; if($resp['code'] != 200) return false; return json_decode($resp['body'], true); } public function getRequests() { return $this-&gt;requests; } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload