【问题标题】:Error 32 from Twitter request using SLRequest with parameters使用带有参数的 SLRequest 来自 Twitter 请求的错误 32
【发布时间】:2014-08-03 00:39:15
【问题描述】:

我正在尝试使用 SLRequest 发出 twitter 请求,但每当我在请求中包含参数时,我得到的响应都是 {"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);
            }];
        }
    }
}];

【问题讨论】:

    标签: objective-c authentication twitter slrequest


    【解决方案1】:

    在我看来,您不能将 @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

    【讨论】:

    • 就是这样,谢谢!不敢相信我没有注意到它
    • :D 我以前也遇到过这种情况,所以不用担心。
    猜你喜欢
    • 2013-11-30
    • 2013-06-01
    • 2018-12-21
    • 1970-01-01
    • 2021-06-05
    • 2018-06-19
    • 2011-06-17
    • 2019-02-24
    • 1970-01-01
    相关资源
    最近更新 更多