2
我正在开发一个iOS应用程序,其中包含用户墙的Facebook供稿。使用图形API使用以下网址:Objective-c facebook facebook api分页
feedURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/feed?
access_token=%@&since=%@&until=%@",kFaceBookID,FBSession.activeSession.accessToken,
[dateRange objectForKey:@"since"], [dateRange objectForKey:@"until"]];
我回来的数据,只有一个结果,并用于寻呼的字典项。当我用“下一个”URL做NSURLRequest时,我得到0结果。如果我将同一个网址剪切并粘贴到网络浏览器中,我会返回25个结果。任何想法为什么?
这里是我使用的代码:我回答我的问题,因为我拿了再看看整个逻辑,并彻底改变了我的方法使用[FBRequestConnection ...]而不是
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *nextPageURL;
NSError *jsonError;
if (!jsonError) {
NSDictionary *rDict = [NSJSONSerialization JSONObjectWithData:_postData
options:0
error:&jsonError];
nextPageURL = [[rDict objectForKey:@"paging"]objectForKey:@"next"];
NSArray *rArray = [rDict objectForKey:@"data"];
DLog(@"Posts Dictionary = %@\n\n",rDict);
for (NSDictionary *rPost in rArray) {
FBPost *post = [[FBPost alloc]initFBPostWithDictionary:rPost];
[feedsArray addObject:post];
}
}
else
{
ALog(@"json error = %@",[jsonError localizedDescription]);
[activity stopAnimating];
NSString *errorMessage = [NSString stringWithFormat:@"Facebook status request failed with error: %@\nCheck your network connection and try again later",[jsonError localizedDescription]];
[self quit:errorMessage];
}
[feedsTable reloadData];
if (nextPageURL && [feedsArray count] < 30) {
DLog(@"Next Feed URL = %@",nextPageURL);
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:nextPageURL]];
if (![[NSURLConnection alloc] initWithRequest:request delegate:self]) {
ALog(@"Connection failed for request: %@",request);
}
}
}
你能展示你的代码来访问下一个URL并获取结果吗? –
在原始问题中添加了代码。 – jangelo42
请注意,反序列化JSON需要在'if(!jsonError')之外发生......' –