2013-07-13 86 views
0

我有一個簡單的Twitter客戶端,用於顯示用戶推文,關注者和關注者。iOS twitter API加載了20多個關注者/關注者/推文

由於某些原因,用戶tweets的count參數被忽略,並且始終只加載20個結果。

下面是代碼:

- (void)getUserTweets { 

    // 1. Create a variable for twitter 
    NSURL *feedURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"]; 

    // 2. Get AppDelegate reference 
    AppDelegate *appDelegate =[[UIApplication sharedApplication] delegate]; 

    // 3. Create NSDictionary for the TWR parameters 
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: self.usernameToLoad, @"screen_name", @"true", @"include_user_entities", @"100", @"count", nil]; 


    // 4. Create TWRequest, with parameters, URL & specify GET method 
    //TWRequest *twitterFeed = [[TWRequest alloc] initWithURL:feedURL parameters:parameters requestMethod:TWRequestMethodGET]; 
    SLRequest *twitterFeed = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:feedURL parameters:params]; 

    // 5. Specify twitter request's account to our app delegate's 
    twitterFeed.account = appDelegate.userAccount; 


    // Making the request 

    [twitterFeed performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 

      // Check if we reached the reate limit 

      if ([urlResponse statusCode] == 429) { 
       NSLog(@"Rate limit reached"); 
       return; 
      } 

      // Check if there was an error 

      if (error) { 
       NSLog(@"Error: %@", error.localizedDescription); 
       return; 
      } 

      // Check if there is some response data 

      if (responseData) { 

       NSError *error = nil; 
       self.userTweets = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; 

      } 
     }); 
    }]; 

} 

這將始終只返回20個結果,即使我設置計數的東西像低1或2.我做錯了什麼定義我的參數?

此外,我試圖加載用戶的追隨者和下面的,但我想加載共200如果每個,但同樣只能載入20

從什麼Twitter的API讀取,它提供自動分頁和使用遊標參數我可以迭代加載所有我想要的數據。

我很難搞清楚這是如何工作的。這裏是我下面的代碼(追隨者與它調用不同的API字符串除外相同)

- (void)getFriends { 

    // 1. Create a variable for twitter 
    NSURL *feedURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/friends/list.json"]; 

    // 2. Get AppDelegate reference 
    AppDelegate *appDelegate =[[UIApplication sharedApplication] delegate]; 

    // 3. Create NSDictionary for the TWR parameters 
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys: self.usernameToLoad, @"screen_name", @"true", @"include_user_entities", nil]; 

    // 4. Create TWRequest, with parameters, URL & specify GET method 
    //TWRequest *twitterFeed = [[TWRequest alloc] initWithURL:feedURL parameters:parameters requestMethod:TWRequestMethodGET]; 
    SLRequest *twitterFeed = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:feedURL parameters:parameters]; 

    // 5. Specify twitter request's account to our app delegate's 
    twitterFeed.account = appDelegate.userAccount; 


    // Making the request 

    [twitterFeed performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 

      // Check if we reached the reate limit 

      if ([urlResponse statusCode] == 429) { 
       NSLog(@"Rate limit reached"); 
       return; 
      } 

      // Check if there was an error 

      if (error) { 
       NSLog(@"Error: %@", error.localizedDescription); 
       return; 
      } 

      // Check if there is some response data 

      if (responseData) { 

       NSError *error = nil; 
       NSDictionary *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; 



       self.userFriends = [TWData objectForKey:@"users"]; 

      } 
     }); 
    }]; 

} 

我不知道如何正確遍歷,因爲Twitter的API返回的光標值我需要去下一個數據。

任何幫助都會很棒,我可能會錯過一些我無法完全理解的邏輯。

在此先感謝!

回答

0

好吧,我也曾經有過在尋呼鳴叫喂同樣的問題,它從來沒有用來更新「max_id」參數,因爲它的值是「NSNumber的」,於是我改到的NSString那麼它的工作完全適合我,交叉檢查再次天氣除NSString以外的任何對象用於請求