// 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 将与响应一起调用。根据您的需要,您将执行以下操作:
- (void)request:(FBRequest*)request didLoad:(id)result {
NSLog(@"didLoad() received result: %@", result);
}
facebook 对象的创建方式如下:
Facebook * facebook = [[Facebook alloc] initWithAppId:kAppID];
可以在此处找到有关如何设置的更多信息:
https://developers.facebook.com/docs/guides/mobile/
根据您的 FQL 查询,您将需要用户的权限。在此处查看权限列表:
https://developers.facebook.com/docs/authentication/permissions/
这里还有一个用于 FQL 查询的测试控制台:
https://developers.facebook.com/docs/reference/rest/fql.query/
如果你想做一个多查询而不是单个查询,它看起来像:
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];