title: Facebook Batch API insight requests
body: <p>For a project I have to grab the insights of a page over a long period of time (e.g. 1-2 years) of facebook.</p>
  
  <p>I first tried to do a single request but it turned out that only requesting </p>
  
  <pre><code>/PAGE_ID/insights?since=xxx&amp;until=xxx
  </code></pre>
  
  <p>doesn't return all the data I want (it somehow supresses data as if there's some limit to the size of the answer).</p>
  
  <p>I then tried to split up the date range (e.g. 01.04.2011-01.04.2011 -> 01.04.2011-01.08.2011-01.12.2011-01.04.2011) which as well, didn't quite work like I wanted it to.</p>
  
  <p>My next approach was to request only the insight values I need, like 'page_stories, page_impressions, ...'. The requests looked like this</p>
  
  <pre><code>/PAGE_ID/insights/page_impressions/day?since=xxx&amp;until=xxx
  </code></pre>
  
  <p>This actually worked but not with ajax. It sometimes seemed to drop some requests (especially if I changed the browser tab in google chrome) and I need to be sure that all requests return an answer. A synchronus solution would just take way too much time considering that one requests needs at least 2 seconds and with a date range of 2 years I may have about 300 single requests this just takes way too long to complete. </p>
  
  <p>Lastly I stumbled over facebook ability to do batch requests which is exactly what I need. It can pack up to 50 requests in one call which significantly lowers the bandwith. And here's where I'm stuck. The facebook api gives some examples on how to use it but none of them worked when I tested them in the Graph Explorer and via the php facebook api sdk. I tried to pack this request</p>
  
  <pre><code>PAGE_ID/insights/page_fan_adds/day?since=1332486000&amp;until=1333695600
  </code></pre>
  
  <p>into a batch request but failed.</p>
  
  <p>It seems that the api is bugged. It's always giving me this error when I'm using a question mark '?' in the 'relative_url' field.</p>
  
  <pre><code>{
    "error": {
      "message": "batch parameter must be a JSON array", 
      "type": "GraphBatchException"
    }
  }
  </code></pre>
  
  <p>Here is what I tried:</p>
  
  <p>These give the 'must be a JSON array' error:</p>
  
  <pre><code>?batch=[{"method":"GET","relative_url":"/PAGE_ID/insights/page_fan_adds/day?since=1332486000&amp;until=1333695600"}]
  </code></pre>
  
  <p>These two actually return data but they are ignoring the parameters:</p>
  
  <pre><code>?batch=[{"method":"GET","relative_url":"/PAGE_ID/insights/page_fan_adds/day","body":"since=1332486000 until=1333695600"}]
  ?batch=[{"method":"GET","relative_url":"/PAGE_ID/insights/page_fan_adds/day","body":"since=1332486000,until=1333695600"}]
  ?batch=[{"method":"GET","relative_url":"/PAGE_ID/insights/page_fan_adds/day","body":{"since":"1332486000","until":"1333695600"}}]
  </code></pre>
  
  <p>And this one tells me that this is an 'Unsupported post request':</p>
  
  <pre><code>?batch=[{"method":"POST","relative_url":"/PAGE_ID/insights/page_fan_adds/day","body":"since=1332486000 until=1333695600"}]
  </code></pre>
  
  <p>Can someone help?</p>