You can do batch requests with the Facebook iOS SDK, but you need to prepare the JSON requests yourself. Here is an example:
- First, create a JSON array string containing 2 JSON requests (see http://developers.facebook.com/docs/api/batch). You can use your preferred JSON API to create these strings.
- Second, create the dictionary of parameters with the "batch" key mapped to the JSON requests string.
- Then, send the request. Note that you need to put something in requestWithGraphPath. I simply put "me" (this request is NOT considered). You also MUST send it as a POST http method.
- Finally, wait for the response array in request:didLoad.
-(void) prepareMyBatchRequest {
NSString *jsonRequest1 = @"{ "method": "GET", "relative_url": "me/friends" }";
NSString *jsonRequest2 = @"{ "method": "GET", "relative_url": "me/albums" }";
NSString *jsonRequestsArray = [NSString stringWithFormat:@"[ %@, %@ ]", jsonRequest1, jsonRequest2];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:jsonRequestsArray forKey:@"batch"];
[facebook requestWithGraphPath:@"me" andParams:params andHttpMethod:@"POST" andDelegate:self];
}
- (void)request:(FBRequest *)request didLoad:(id)result {
NSArray *allResponses = result;
for ( int i=0; i < [allResponses count]; i++ ) {
NSDictionary *response = [allResponses objectAtIndex:i];
int httpCode = [[response objectForKey:@"code"] intValue];
NSString *jsonResponse = [response objectForKey:@"body"];
if ( httpCode != 200 ) {
NSLog( @"Facebook request error: code: %d message: %@", httpCode, jsonResponse );
} else {
NSLog( @"Facebook response: %@", jsonResponse );
}
}
}
Concerning your other question, I don't know (try to ask other questions in distinct posts so it's easier to follow-up).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…