![](/img/trans.png)
[英]Linkedin API 401 [unauthorized]. (iOS with OAuthStarterKit) Error
[英]401 Unauthorized error using twitter API
對於此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);
}
您確定請求已簽名嗎? 您為什么不只使用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.