2013-11-23 44 views
1

我使用Facebook SDK 3.10.0 for iOS。當我試圖讓用戶新聞推送,我有一個問題: 在Facebook上要求:Facebook API分頁不起作用

[FBRequest requestForGraphPath:@"me/home"] 

我得到的響應與我需要和信息關於分頁的所有數據:

data = (
    "A LOT OF USER DATA" 
); 
paging =  { 
    next = "https://graph.facebook.com/{MY_USER_ID}/home?format=json&access_token={ACCESS_TOKEN}&limit=25&until=1385113385"; 
    previous = "https://graph.facebook.com/{MY_USER_ID}/home?format=json&access_token={ACCESS_TOKEN}&limit=25&since=1385206398&__previous=1"; 
}; 

但當我嘗試使用下一個鏈接和AFHTTPRequestOperation獲得信息:

AFHTTPRequestOperation *newDataOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 
    newDataOperation.responseSerializer = [AFJSONResponseSerializer serializer]; 
    [newDataOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 
     NSLog(@"%@", responseObject); 
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
     NSLog(@"Next page retrieving error = %@", error); 
    }]; 

我得到空的JSON

data =  (
); 

我已經使用Facebook的訪問令牌Debugger和結果:

Access Token Debugger Result

而且有奇怪的訪問令牌,我開始使用圖形API瀏覽器不同於我進入我的應用程序。令牌這是我從圖形API Explorer的工作完全正常,但是當我tesetd令牌從應用程序的結果是一樣的:我的/ home工作 enter image description here下一個鏈接返回空:

enter image description here

回答

1
And there is strange thing access token which i get using Graph Api Explorer 
differs from which i get in my app. 

這其實並不奇怪。訪問令牌將根據您從瀏覽器右上角選擇的應用程序類型而改變。

Facebook API Pagination doesn't work 

我在Graph API中看到了很多關於分頁問題的問題,奇怪的是問題還沒有解決呢!您可以嘗試使用Offset based pagination。例如,在URL中設置limit=100&offset=0。我知道這在新聞饋送的情況下沒有意義,但在大量數據的情況下它通常工作正常。

+0

實測值類似的問題[鏈接](http://stackoverflow.com/questions/10898998/calling-facebook-news-feed-me-home-with-until-parameter-returns-limit- 2-each) –

+0

我不明白爲什麼要求** /我/家**圖形Api Explorer應用程序返回鏈接**下一個**的工作,但是當我選擇我的應用程序在圖形Api Explorer鏈接**下一個**不會返回任何數據... o_O –

+0

我知道。有一些錯誤。你會在SO上看到很多關於它的問題,這些問題沒有任何具體的答案。 –

0

對於Facebook的分頁我會建議使用蘋果機類的

使用nextPageURL變量緩存從JSON響應下一個URL,並指定給下一個API請求的URL字符串,如果nextPageURL不是零和使用下面的一段的代碼:

if (self.nextPageURL) { 
    // urlString is the first time formulated url string 
    urlString = self.nextPageURL; 
} 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]]; 
[NSURLConnection sendAsynchronousRequest:request queue:networkQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
    if (error) { 
     DDLogVerbose(@"FACEBOOK:Connection error occured: %@",error.description); 
    }else{ 
     isRequestProcessing = NO; 
     NSDictionary *resultData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil]; 
     DDLogVerbose(@"parsed data is %@",resultData); 
     self.nextPageURL = resultData[@"paging"][@"next"]; 
     // do your customisation of resultData here. 
    } 
}];