objective-cauthenticationtwitterslrequest

Error 32 from Twitter request using SLRequest with parameters


I'm trying to make a twitter request using SLRequest but whenever I include parameters in the request, the response I get back is {"errors":[{"message":"Could not authenticate you","code":32}]}. If I don't include parameters the request works as expected.

I've tried including the parameters as a query string in the URL but it made no difference.

Here's my code:

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

[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
    if (granted) {
        NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType];

        if (twitterAccounts.count == 0) {
            NSLog(@"There are no Twitter accounts configured. You can add or create a Twitter account in Settings.");
        }
        else {
            ACAccount *twitterAccount = [twitterAccounts firstObject];

            SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/home_timeline.json"] parameters:@{@"count": @10}];
            request.account = twitterAccount;

            [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

                NSLog(@"%@", responseString);
            }];
        }
    }
}];

Solution

  • Looks to me like you can't pass the @10 as an integer - try instead passing it as a string: @"10".

    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET 
                          URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/home_timeline.json"]
                          parameters:@{@"count": @"10"}];
                                                // ^
    

    Here's a Twitter doc with an example