使用带参数的SLRequest的Twitter请求出错32

时间:2014-06-12 15:46:04

标签: objective-c authentication twitter slrequest

我正在尝试使用SLRequest发出推文请求,但每当我在请求中包含参数时,我得到的响应是{"errors":[{"message":"Could not authenticate you","code":32}]}。如果我不包含参数,请求将按预期工作。

我已尝试将参数作为查询字符串包含在URL中,但没有区别。

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

在我看来,你无法将@ 10作为整数传递 - 请尝试将其作为字符串传递:@“10”。

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

这是Twitter doc with an example