2013-04-09 19 views
1

我使用以下twitter api獲取好友列表: https://api.twitter.com/1.1/friends/list.json如何在twitter中處理多個SLRequest以獲取好友列表?

並使用[SLRequest performRequestWithHandler:^(NSData * responseData,NSHTTPURLResponse * urlResponse,NSError * error)來獲取響應數據,並在performRequestWithHandler塊中執行UI更改和模型數據更改。

但是最大的一個請求只能檢索到20個朋友(如果將api中的遊標參數設置爲-1)。

我可以使用api的遊標參數發送請求,以獲得下20個朋友,等等,直到遊標值爲0. 遊標參數可以設置爲響應數據中的'next_cursor'參數先前的請求。

但是我不知道如何在先前請求的performRequestWithHandler調用另一個SLRequest用,直到前一個請求的響應數據的「next_cursor」值爲0

誰能告訴我怎麼走都使用SLRequest或使用任何其他方式的朋友。

任何幫助表示讚賞。

謝謝。

回答

1

您可以在獲取Twitter朋友的回覆後,在請求處理程序中調用下一個請求。

對不起,不詳細。我以爲你會明白。 這是代碼。

ACAccountStore *account = [[ACAccountStore alloc] init]; 
     ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

     // Request access from the user to access their Twitter account 
     [account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) 
     { 
      // Did user allow us access? 
      if (granted == YES) 
      { 
       // Populate array with all available Twitter accounts 
       NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType]; 

       // Sanity check 
       if ([arrayOfAccounts count] > 0) 
       { 

        [self postRequest]; 

       } 
      } 
     }]; 

- (void)PostRequest 
{ 
     // Keep it simple, use the first account available 
        ACAccount *acct = [arrayOfAccounts objectAtIndex:0]; 

        NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init]; 
        [tempDict setValue:@"Posting video" forKey:@"status"]; 

        // Build a twitter request 

        SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"] parameters:tempDict]; 

        [postRequest setAccount:acct]; 

        [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
         NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]); 
         NSString *output = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
         NSLog(@"%@", output); 
**// calling this again and again will help you with multiple post request.** 
[self postRequest] 
        }]; 
} 

類似的事情也可以爲朋友列表完成。

希望我幫了忙。

+2

請您詳細說明您的意思,如果沒有,請將其轉移到評論。 – 2013-04-09 08:19:02

+1

@swati這是一個更好的 – Khushboo 2013-04-09 09:01:15

+0

這改變了用戶狀態,不檢索用戶關注者。 – Borzh 2016-03-03 22:55:34

相關問題