1
votes

I m using the following twitter api to get the friends list: https://api.twitter.com/1.1/friends/list.json?

And using [SLRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) to get the response data, and perform UI Changes and model data changes in performRequestWithHandler block.

But a single request at the maximum retrieves only 20 friends.(if you set the cursor parameter in api to -1).

I can use the cursor parameter of the api to send request to get the next 20 friends and so on until the cursor value is 0. cursor parameter can be set to the 'next_cursor' parameter in the response data of the previous request.

But i m not aware of how to call another SLRequest with in the performRequestWithHandler of the previous request, until the 'next_cursor' value in response data of previous request is 0.

Can anybody tell me how to get all the friends using SLRequest or using any other way.

Any help is appreciated.

Thank you.

1

1 Answers

1
votes

u can call the next request in the request handler just after you get the response of twitter friends.

Sorry for not elaborating. I thought you would understand. Here is the code.

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

Similar thing can be done for friend list too.

Hope I helped.