Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

iphone - Facebook connect Batch requests and FQL error problem

I'm developing an iPhone iOS app with FB connect.

I'm trying to get a lot of data for each of my friends, and multiple requests are needed.

I wonder if there's a way using batch requests in the iOS SDK?

and the other problem with FQL multi-queries. The following query is working only for a limit of one friend! weird.

SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 2)

it returns the error The operation couldn’t be completed. (facebookErrDomain error 1.) According this example of facebook it should have been working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...