JoshDG
JoshDG

Reputation: 3931

Facebook batch request in objective-c

Has anyone had any request with this? I can't quite figure it out and right now I'm sending like 75 separate HTTP requests which doesn't seem smart, and I run into issues with such a big multiquery.

(Although, with a batch request I'm worried there's a bigger chance of timing out because its sending back a bigger result which can be lost over 3G).

Has anyone been able to code a batch request in objective-c OR do you have other suggestions for very large queries? I know its proper form to attach code but I couldn't even figure out where to start.

Upvotes: 3

Views: 1544

Answers (1)

MByD
MByD

Reputation: 137362

There is an option for performing batch request with the Graph API, as described at the docs:

curl \
    -F 'access_token=…' \
    -F 'batch=[ \
            {"method": "GET", "relative_url": "me"}, \
            {"method": "GET", "relative_url": "me/friends?limit=50"} \
        ]'\
    https://graph.facebook.com

Note that there is current limit of 50 operations for a single batch request.

Implementation on Facebook iOS SDK will look somewhat like this (where facebook is your Facebook instance):

NSString *req01 = @"{ \"method\": \"GET\", \"relative_url\": \"me\" }";
NSString *req02 = @"{ \"method\": \"GET\", \"relative_url\": \"me/friends?limit=50\" }";
NSString *allRequests = [NSString stringWithFormat:@"[ %@, %@ ]", req01, req02];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:allRequests forKey:@"batch"];
[facebook requestWithGraphPath:@"me" andParams:params andHttpMethod:@"POST" andDelegate:self];

Upvotes: 9

Related Questions