2011-05-16 68 views
8

我正在尋找一些關於如何通過iOS SDK向Facebook發送多查詢fql請求的文檔或示例代碼。 我發現了一些較舊的樣本,但它們不適合我。 我填寫了一個NSDictionary與查詢,我嘗試通過 [[FBRequest requestWithDelegate:self] call:@"facebook.fql.multiquery" params:params];發送請求,如我已閱讀的示例中所述,但我得到一個「無法識別的選擇器發送到類」的錯誤,我無法找到「requestWithDelegate」方法在FBRequest.h中。它是否被棄用? 對此的一些幫助將不勝感激!iOS SDK中的FQL多查詢

+0

您是否檢出了Facebook IOS SDK?這個開源的iOS庫允許您將Facebook集成到iOS應用程序中,包括iPhone,iPad和iPod touch。該SDK是輕量級的,沒有外部依賴性。入門相對簡單。 https://github.com/facebook/facebook-ios-sdk/ – fuzz 2011-05-17 06:32:40

回答

14
// 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將與響應調用。根據您的需求,你會做這樣的事情:

Facebook * facebook = [[Facebook alloc] initWithAppId:kAppID]; 
如何設置此

更多信息可以在這裏找到: https://developers.facebook.com/docs/guides/mobile/

- (void)request:(FBRequest*)request didLoad:(id)result { 
    NSLog(@"didLoad() received result: %@", result); 
} 

Facebook的對象像創建

而根據您的FQL查詢,您將需要來自用戶的權限。見權限列表中的位置: https://developers.facebook.com/docs/authentication/permissions/

還爲FQL測試控制檯查詢這裏: https://developers.facebook.com/docs/reference/rest/fql.query/

如果你想要做一個Multiquery而不是一個單一的查詢,它看起來像:

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]; 
+1

什麼是queryID和queryName?你能解釋一下嗎?謝謝....我用你提到的多查詢,但返回null。 – Maulik 2013-04-19 05:28:45