简体   繁体   中英

FQL in the SDK 3.0 Beta for iOS

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM