2

我正在开发一个 iOS 应用程序,其中包括用户墙的 facebook 提要。使用带有以下 URL 的图形 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 个结果。如果我将相同的 URL 剪切并粘贴到网络浏览器中,我会得到 25 个结果。关于为什么的任何想法?

这是我正在使用的代码:

- (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);
        }

    }

}
4

1 回答 1

1

我正在回答我自己的问题,因为我重新审视了整个逻辑并完全改变了我使用 [FBRequestConnection...] 的方法。如果有人感兴趣,这是代码。请注意,我一次获取一周的提要消息以提高 tableview 性能。

- (void) fetchFBFeedsForDateRange:(NSDictionary *)dateRange;
{
    _postData = [[NSMutableData alloc]init];
    //since, until is a decremented one week at a time date range. 
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            [dateRange objectForKey:@"since"], @"since",
                            [dateRange objectForKey:@"until"], @"until",
                            nil];
    NSString *gPath = [NSString stringWithFormat:@"%@/feed",kFaceBookID];
    [FBRequestConnection startWithGraphPath:gPath
                                 parameters:params
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              if (!error) {
                                  NSArray *rArray = [result objectForKey:@"data"];
                                  //DLog(@"Posts Array = %@\n\n",rArray);
                                  for (NSDictionary *rPost in rArray) {
                                      FBPost *post = [[FBPost alloc]initFBPostWithDictionary:rPost];
                                      if (post.type) {
                                          if (!post.skip) {
                                              [feedsArray addObject:post];
                                          }
                                      }
                                  }
                                [feedsTable reloadData];
                                  if ([feedsArray count] <  kFaceBookMaxPostsToDisplay) {
                                      [self performSelector:@selector(fetchPreviousWeek)];
                                  }
                                  else
                                  {
                                      [activity stopAnimating];
                                  }
                              }
                              else
                              {
                                  [activity stopAnimating];
                                  NSString *errorMessage = [NSString stringWithFormat:@"Facebook status request failed with error: %@\nCheck your network connection and try again later",[error localizedDescription]];
                                  [self quit:errorMessage];

                              }

                          }];
}
于 2012-12-23T19:48:00.730 回答