Facebook连接批量请求和FQL错误问题
问题描述:
我正在开发一个带有FB连接的iPhone iOS应用程序。Facebook连接批量请求和FQL错误问题
我想为我的每个朋友获取大量数据,并且需要多个请求。
我不知道在iOS SDK中是否有使用批量请求的方法?
和FQL多查询的其他问题。以下查询仅适用于一个朋友的限制!奇怪的。
SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 2)
则返回错误The operation couldn’t be completed. (facebookErrDomain error 1.)
根据本example of facebook它应该一直在努力。
答
您可以使用Facebook iOS SDK进行批量请求,但您需要自己准备JSON请求。下面是一个例子:
- 首先,创建含有2个JSON请求(见http://developers.facebook.com/docs/api/batch)JSON数组字符串。您可以使用您的首选JSON API来创建这些字符串。
- 其次,使用映射到JSON请求字符串的“批处理”键创建参数字典。
- 然后发送请求。请注意,您需要将某些东西放在requestWithGraphPath中。我只是把“我”(这个请求不考虑)。你也必须以POST方法发送它。
- 最后,在request:didLoad中等待响应数组。
-(void) prepareMyBatchRequest {
NSString *jsonRequest1 = @"{ \"method\": \"GET\", \"relative_url\": \"me/friends\" }";
NSString *jsonRequest2 = @"{ \"method\": \"GET\", \"relative_url\": \"me/albums\" }";
NSString *jsonRequestsArray = [NSString stringWithFormat:@"[ %@, %@ ]", jsonRequest1, jsonRequest2];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:jsonRequestsArray forKey:@"batch"];
[facebook requestWithGraphPath:@"me" andParams:params andHttpMethod:@"POST" andDelegate:self];
}
- (void)request:(FBRequest *)request didLoad:(id)result {
NSArray *allResponses = result;
for (int i=0; i < [allResponses count]; i++) {
NSDictionary *response = [allResponses objectAtIndex:i];
int httpCode = [[response objectForKey:@"code"] intValue];
NSString *jsonResponse = [response objectForKey:@"body"];
if (httpCode != 200) {
NSLog(@"Facebook request error: code: %d message: %@", httpCode, jsonResponse);
} else {
NSLog(@"Facebook response: %@", jsonResponse);
}
}
}
关于您的其他问题,我不知道(试着问在不同岗位的其他问题,因此更容易跟进)。
谢谢!你知道为什么图API请求参数像极限,并且因为有问题吗?它使用的是“events?limit ..”而不是“events&limit ..”,它不会获得更多的参数。至于'since =今天'它会带来甚至老的事件! Tnx – 2011-04-01 07:06:45
这里的facebook对象是什么 - [facebook requestWithGraphPath:@“me”andParams:params andHttpMethod:@“POST”andDelegate:self];它是FBSession还是FBRequest? – verma 2012-10-07 22:16:47
@verma我想知道同样的问题 – Ricardo 2015-02-16 15:21:18