在objective-c中的Facebook批量请求

Jos*_*hDG 3 xcode cocoa-touch objective-c facebook-graph-api

有人对此有任何要求吗?我无法弄明白,现在我发送了75个单独的HTTP请求,这看起来并不聪明,而且我遇到了如此大的多重问题.

(虽然有批量请求,我担心超时的可能性更大,因为它会发回更大的结果,而这可能会在3G上丢失).

有没有人能够在objective-c中编写批处理请求?或者您对非常大的查询有其他建议吗?我知道它附加代码的正确形式,但我甚至无法弄清楚从哪里开始.

MBy*_*ByD 8

可以使用Graph API执行批量请求,如文档中所述:

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

请注意,单个批处理请求的当前限制为50个操作.

Facebook iOS SDK上的实现看起来有点像这样(facebook你的Facebook实例在哪里):

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];
Run Code Online (Sandbox Code Playgroud)