【问题标题】:Facebook FQL multiquery in iOS SDKiOS SDK 中的 Facebook FQL 多查询
【发布时间】:2011-05-16 19:47:44
【问题描述】:

我正在寻找一些关于如何通过 iOS SDK 向 Facebook 发送多查询 fql 请求的文档或示例代码。 我找到了一些较旧的样本,但它们对我不起作用。 我已经用查询填充了NSDictionary,我尝试通过发送请求 [[FBRequest requestWithDelegate:self] call:@"facebook.fql.multiquery" params:params];,如我阅读的示例中所述,但我收到“无法识别的选择器发送到类”错误,并且我也无法在 FBRequest.h 中找到“requestWithDelegate”方法。是否已弃用? 对此提供一些帮助将不胜感激!

【问题讨论】:

  • 你检查过Facebook IOS SDK吗?这个开源 iOS 库允许您将 Facebook 集成到您的 iOS 应用程序中,包括 iPhone、iPad 和 iPod touch。 SDK 是轻量级的,没有外部依赖。入门相对容易。 github.com/facebook/facebook-ios-sdk

标签: iphone objective-c facebook facebook-fql fql.multiquery


【解决方案1】:
// 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];

【讨论】:

  • 什么是 queryID 和 queryName ?你能解释一下吗?谢谢....我使用你提到的多查询,但返回 null。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多