1

我正在使用以下 twitter api 来获取好友列表: https ://api.twitter.com/1.1/friends/list.json ?

并使用 [SLRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 获取响应数据,并在 performRequestWithHandler 块中执行 UI 更改和模型数据更改。

但是单个请求最多只能检索20个朋友。(如果您将api中的游标参数设置为-1)。

我可以使用api的cursor参数发送请求获取下20个好友,以此类推,直到cursor值为0。 cursor参数可以设置为上一个请求的响应数据中的'next_cursor'参数。

但我不知道如何在前一个请求的 performRequestWithHandler 中调用另一个 SLRequest,直到前一个请求的响应数据中的“next_cursor”值为 0。

谁能告诉我如何使用 SLRequest 或任何其他方式获得所有朋友。

任何帮助表示赞赏。

谢谢你。

4

1 回答 1

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]
                     }];
}

朋友列表也可以做类似的事情。

希望我有所帮助。

于 2013-04-09T07:55:31.003 回答