ios - 使用 twitter API 出现 401 未经授权的错误
<p><p>对于这个 twitter API 请求,我总是收到 <code>401 Unauthorized</code> 响应。这很令人困惑,因为我有一个 Twittersession 并且正在签署请求。提前致谢。</p>
<pre><code> NSURL *retweetAPIURL = ];
NSMutableURLRequest *request = ;
request.HTTPMethod = @"POST";
if (self.twitterSession) {
;
AFHTTPRequestOperation *operation = [ initWithRequest:request];
operation.responseSerializer = ;
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
block(nil, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
block(error, nil);
}];
[ addOperation:operation];
} else {
block(, nil);
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您确定正在签署请求吗?为什么不直接使用 <code>SLRequest</code>?</p>
<pre><code>NSURL *retweetAPIURL = ];
ACAccount *account = // ...;
SLRequest *request = ;
request.account = account;
NSURLRequest *preparedURLRequest = ;
// create your AFHTTPRequestOperation using preparedURLRequest
</code></pre></p>
<p style="font-size: 20px;">关于ios - 使用 twitter API 出现 401 未经授权的错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22129292/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22129292/
</a>
</p>
页:
[1]