401使用twitter API未经授权的错误

时间:2014-03-02 15:08:15

标签: ios objective-c twitter parse-platform

对于此Twitter API请求,我总是得到401 Unauthorized响应。这很令人困惑,因为我有一个Twitter会话并且正在签署请求。提前谢谢。

    NSURL *retweetAPIURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json", tweetID]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:retweetAPIURL];
request.HTTPMethod = @"POST";

if (self.twitterSession) {

    [self.twitterSession signRequest:request];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        block(nil, responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        block(error, nil);
    }];

    [[NSOperationQueue mainQueue] addOperation:operation];
} else {
    block([self createErrorWithMessage:NSLocalizedString(NSLocalizedString(@"TWITTER LOGIN ERROR", nil), nil)], nil);
}

1 个答案:

答案 0 :(得分:1)

您确定要求签名吗?你为什么不用SLRequest

NSURL *retweetAPIURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json", tweetID]];
ACAccount *account = // ...;
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:retweetAPIURL parameters:nil];
request.account = account;

NSURLRequest *preparedURLRequest = [request preparedURLRequest];

// create your AFHTTPRequestOperation using preparedURLRequest