【问题标题】:How to process multiple SLRequest to get friends list in twitter?如何处理多个 SLRequest 以获取 Twitter 中的好友列表?
【发布时间】:2013-03-31 11:38:17
【问题描述】:

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

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

但是一个请求最多只能检索20个好友。(如果你将api中的cursor参数设置为-1)。

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

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

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

感谢任何帮助。

谢谢。

【问题讨论】:

    标签: objective-c multithreading ios6 twitter


    【解决方案1】:

    你可以在收到推特朋友的回复后在请求处理程序中调用下一个请求。

    抱歉没有详细说明。我以为你会明白的。 这是代码。

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

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

    希望我能帮上忙。

    【讨论】:

    • 您能否举例说明您的意思,如果没有,请将其移至评论。
    • @swati 这个更好
    • 这会改变用户状态,不会检索用户关注者。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 2013-06-22
    • 1970-01-01
    • 2011-12-12
    • 2014-01-22
    • 2014-12-05
    相关资源
    最近更新 更多