3

I cannot find the requestWithMethodName method anywhere in the new 3.0 Beta SDK for iOS. Did you guys drop it and if so, how are we supposed to send fql queries to the API now? Or were those deprecated?

Sebastian
  • 2,889
  • 4
  • 34
  • 37

1 Answers1

5

You may make requests with method names using:

[[[FBRequest alloc] initWithSession:...
                         restMethod:... 
                         parameters:... 
                         HTTPMethod:...]
 startWithCompletionHandler:...];

However, you may also make FQL queries using the FQL graph object, like so:

FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
[fql.parameters setObject:@"SELECT uid, name, pic_square FROM user WHERE uid = me()"
                          @"OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
                   forKey:@"q"];

[fql startWithCompletionHandler:^(FBRequestConnection *connection, 
                                  id result, 
                                  NSError *error) {
    if (result) {
        NSLog(@"result:%@", result);
    }
}];

Finally, if you want to batch several requests, rather than call start on the FBRequest object, you can create an FBRequestConnection object and add several requests before calling start, like so:

FBRequestConnection *conn = [[FBRequestConnection alloc] init];
[conn addRequest:fqlRequest1 completionHandler:^(FBRequestConnection *connection, 
                                                 id result,
                                                 NSError *error) {
    if (result) {
        NSLog(@"result:%@", result);
    }
}];

[conn addRequest:fqlRequest2 completionHandler:^(FBRequestConnection *connection,
                                                 id result,
                                                 NSError *error) {
    if (result) {
        NSLog(@"result:%@", result);
    }
}];

[conn start];

The SDK takes care of serializing the requests into a single batch request to the server, as well as parsing the response and calling the correct handler with the matching result or error.

Note

In cases where you can use either the graph or rest APIs to achieve the same results, use of the graph API is preferred over use of the rest API. We are in the process of deprecating the old rest API

Jason Clark
  • 1,343
  • 8
  • 8
  • thx Jason, I'll try that right away. Is the "batching requests" functionality the same as the fql.multiquery? Or does fql.multiquery still exist as a valid GraphPath? – Sebastian Jul 15 '12 at 12:21
  • Hi Sebastian, the batch functionality of the SDK uses graph API batch requests. It is different from fql.multiquery, but as you suggested, it can be used to issue an fql.multiquery. The "path" in that case would be method/fql.multiquery. The following topic has the details: https://developers.facebook.com/docs/reference/api/batch/ – Jason Clark Jul 15 '12 at 15:46
  • Hi @Sebastian, just following up to see if the answer/comment helped out with your question. Thanks! – Jason Clark Jul 19 '12 at 14:23
  • @JasonClark, I am curious about the preferred way to make the equivalent of an fql query like this, using the iOS SDK v3.1. Here's my old fql.multiquery: "{\"me\":\"SELECT uid, first_name, last_name, pic, pic_big, is_app_user FROM user WHERE uid = me()\",\"friends\":\"SELECT uid, first_name, last_name, pic, pic_big, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())\"}"; ... the point is to get my own details followed by those of my friends, with just these fields. It seems pretty inefficient the way I'm doing it now... – sounder_michael Oct 13 '12 at 00:05
  • Jason it looks like the Scrumptious sample in the Facebook IOS SDK 3.0 beta is similar to the code you posted. I just integrated that code into my app and I notice some leaks and I don't know the best place to release objects. For example, `[[FBRequest alloc] initWithSession]` and `[[FBRequestConnection alloc] init]` never gets released in the Scrumptious sample code. I'm not sure if I should declare a `FBRequest` and `FBRequestConnection` in the header and release in `dealloc`? I also tried releasing the `FBRequestConnections` in the completion blocks which doesn't seem to work. – Primico Jul 24 '12 at 03:19