Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restfb - Get multiple connections in one call

I am using restfb to search for connections using search strings. Based on the example on the restfb.com website, searching is just another example of fetching a connection. I have gotten this to work so far. That is, I can search for example "honda" under "me/home" or "me/posts", successively.

What I cannot figure out is how to combine multiple searches (that is, fetch multiple connections) in a single call. For example, I want to search for "honda" under "me/home" as well as under "me/posts", in a single call.

The restfb.com example for fetching multiple objects is given as follows:

FetchObjectsResults fetchObjectsResults = facebookClient.fetchObjects(Arrays.asList("me", "cocacola"), ....

However, I do not seem to see anything like "fetchConnections" that may enable to retrieve multiple connections, and therefore enable me to combine multiple connection searches in one call.

Any ideas on how I can combine multiple fetchConnections in a single call?

Thanks in advance for the help!

Mohammad

like image 816
rc1 Avatar asked Dec 17 '25 03:12

rc1


1 Answers

You want to use the batch request object. Something such as the following should work

LinkedList<BatchRequest> request = new LinkedList<BatchRequest>();
List<Long> working = new LinkedList<Long>();
BatchRequest temp = new BatchRequest.BatchRequestBuilder("me").parameters(Parameter.with("limit", 20)).build();
BatchRequest.BatchRequestBuilder("cocacola").parameters(Parameter.with("limit", 20)).build();

Then to make the requests just do the following

List<BatchResponse> response = facebookClient.executeBatch(request, Collections.<BinaryAttachment>emptyList());

Replace me and cocacola with the queries you actually want to make. The restfb page documents how to make these batch requests. The main thing to realise is that you can only put 50 requests per batch request.

like image 140
Steve Avatar answered Dec 19 '25 23:12

Steve