2014-03-02 104 views
2

我总是得到这个twitter API请求401 Unauthorized响应。这是令人困惑的,因为我有一个推特会议并正在签署请求。提前致谢。401未经授权的错误使用Twitter API

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

您确定请求正在签名?你为什么不使用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 
+0

我会尝试下一个解决方案但问题是我使用Parse.com后端和登录Twitter的应用程序(不登录设置)。所以,你会告诉我如何检查请求是否签署? –

相关问题