3

Long shot, but I have a list of about 5,000 Facebook IDs that I'd like to get openGraph data from. I only want to get data from public pages, rather than from personal fb accounts.

I understand that in the latest openGraph API you get the following error if you try to look up a username:

 "message": "(#803) Cannot query users by their username (xxxxx)"

This is fine, as mentioned I'm not interested in users, just pages. However, I'm trying to batch my requests together into lots of 50 so I can get my data as quickly as possible (at 5,000 pages that's 1 minute 40 seconds, otherwise according to various sources I'd need to do 1 individual request every second, or 1hr 23 minutes).

I'm wondering if there's ANY way that I can send a batched GET request to the Facebook graph API that says "if there's an error with a particular ID, ignore it and return the rest"?

Or otherwise, is there some way to verify which IDs are pages (acceptable for graph) and which are users, so that I can batch the page data together?

JVG
  • 20,198
  • 47
  • 132
  • 210
  • Doesn't matter of you are doing several requests or one batch request. When it comes to limitations both effect the limit the same way – WizKid Aug 30 '15 at 19:45
  • @WizKid Well a batch request counts as 1 request towards the limit, rather than 50 individual requests, so this is quite an important distinction. In one minute you could get 60 individual usual profile objects, or you could get 3000 by batching them in lots of 50. – JVG Aug 31 '15 at 04:13
  • No it doesn't. A batch request with 50 request in it counts as 50 requests – WizKid Aug 31 '15 at 04:56
  • @WizKid Perhaps my terminology is wrong. According to this answer, *About 600 calls per 600 seconds* is where they'll cut you off - http://stackoverflow.com/questions/8713241/whats-the-facebooks-graph-api-call-limit - the batch request appears to count as 1 call, rather than 50 calls. At least, I haven't run into any rate limiting on my various tests! – JVG Aug 31 '15 at 06:18
  • I just told you batch request doesn't count as 1. It count as how many requests are in it. – WizKid Aug 31 '15 at 13:40
  • Which programming language do you use? If it's python, it can be easily solved by using Facepy library – Aminah Nuraini Feb 23 '16 at 08:23
  • @WizKid According to https://developers.facebook.com/docs/graph-api/making-multiple-requests/ "batch requests will be counted as a single request for rate limiting purposes.", but also "each call within the batch is counted separately for the purposes of calculating API call limits and resource limits". Not clear to me! – IanS Jul 10 '19 at 08:47
  • File a documentation bug then. – WizKid Jul 10 '19 at 17:35
  • As you can see here: https://developers.facebook.com/docs/graph-api/overview/rate-limiting (search for FAQ in the bottom of the page) the graph api call with ?id=id1,id2,id3 will count 3 api calls, the same if using batch calls with separated calls to /id1, /id2, /id3 . – Valery Patskevich Oct 20 '21 at 13:19

1 Answers1

0

I've found a solution to this! Thankfully, as mentioned not being able to batch requests would turn a 1.5minute operation into a 1.5 HOUR operation.

For me the solution was Node Fbgraph. It's a lovely little module that lets you batch requests together. I went from this:

 request('https://graph.facebook.com/v2.2/?fields=id,name,website,likes,about,talking_about_count,location&ids=' <<lots of user ids>>'&access_token='<<token>>)

to:

    var graph = require('fbgraph');
    var token = "whatever";
    graph.setAccessToken(token);

    var arr = ['name1','name2','name3','name4']

    var params = "fields=id,name,website,likes,about,talking_about_count,location";
    var batchArr = [];
    for(var i = 0; i<arr.length; i++){
    tempObj = {
      method: "GET",
      relative_url: arr[i] + "?" + params
   }

   batchArr.push(tempObj);
}


graph.batch(batchArr, function(err, res) {
  console.log(res);
  // res = [{headers and body for #1}, {headers and body for #2} ... etc]
});

This allows the 'disallowed' usernames to fail and get an #803 error, but lets all of the other ones succeed so you can use that data as you like.

JVG
  • 20,198
  • 47
  • 132
  • 210