iOS SDK中的Facebook FQL多重查询 [英] Facebook FQL multiquery in iOS SDK
问题描述
我正在寻找一些关于如何通过iOS SDK向Facebook发送多查询fql请求的文档或示例代码。
我发现一些较旧的样本,但它们不适合我。
我填充了一个 NSDictionary
与查询,我尝试通过
发送请求[[FBRequest requestWithDelegate:self]调用:@facebook.fql.multiqueryparams:params];
,如我所读的示例中所述,但是我收到一个无法识别的选择器发送到类错误,我找不到请求方式在FBRequest.h中。是不是弃用?
一些帮助将非常感谢!
I am looking for some documentation or sample code on how to send multiquery fql requests to Facebook via iOS SDK.
I found some older samples but they doesnt work for me.
I have populated an NSDictionary
with the queries and I try to send the request via
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.multiquery" params:params];
, as stated in the samples I have read, but I get an "unrecognized selector sent to class" error and I cant find the "requestWithDelegate" method in FBRequest.h either. Is it deprecated?
Some help on this would be very appreciated!
推荐答案
// Construct your FQL Query
NSString* fql = [NSString stringWithFormat:@"SELECT uid, name, hometown_location from user where uid IN (SELECT uid2 FROM friend WHERE uid1=%lld) and hometown_location != '' ORDER BY rand() limit 4", facebookId];
// Create a params dictionary
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"query"];
// Make the request
[facebook requestWithMethodName:@"fql.query" andParams:params andHttpMethod:@"GET" andDelegate:self];
代表FBRequestDelegate将与响应一起调用。根据您的需要,您可以执行以下操作:
The the delegate FBRequestDelegate will be call with the response. Depending on your needs, you'll do something like:
- (void)request:(FBRequest*)request didLoad:(id)result {
NSLog(@"didLoad() received result: %@", result);
}
Facebook对象创建如下:
The facebook object is created like:
Facebook * facebook = [[Facebook alloc] initWithAppId:kAppID];
有关如何设置此项的更多信息,可以在这里找到:
https://developers.facebook.com/docs/guides/mobile/
More info on how to set this up can be found here: https://developers.facebook.com/docs/guides/mobile/
根据您的FQL查询,您将需要用户的权限。请参阅权限列表:
https://developers.facebook.com/docs / authentication / permissions /
And depending on your FQL query, you will need permissions from the user. See the list of permissions here: https://developers.facebook.com/docs/authentication/permissions/
这里还有一个用于FQL查询的测试控制台:
https://developers.facebook.com/docs/reference/rest/fql.query/
There is also a test console for FQL queries here: https://developers.facebook.com/docs/reference/rest/fql.query/
如果你想做一个Multiquery,而不是一个单一的查询,它将如下所示:
And if you want to do an Multiquery instead of a single query, it would look like:
NSString* fql1 = [NSString stringWithFormat:
@"select uid2 from friend where uid1 == %lld order by rand() limit 10", facebookId];
NSString* fql2 = [NSString stringWithFormat:
@"select uid, name from user where uid in (select uid2 from #queryID)"];
NSString* fql3 = [NSString stringWithFormat:
@"select uid, status_id, message from status where uid in (select uid from #queryName) limit 1"];
NSString* fql = [NSString stringWithFormat:
@"{\"queryID\":\"%@\",\"queryName\":\"%@\",\"queryStatus\":\"%@\"}",fql1,fql2,fql3];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"queries"];
[facebook call:@"fql.multiquery" params:params];
这篇关于iOS SDK中的Facebook FQL多重查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!