我正在尝试执行反向oauth以获取服务器的twitter访问令牌。iOS Twitter SLRequest返回url域错误-1012
我想通了如何提交请求和接收响应,但是当我做,它给了我这个错误:
Error: The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
我看这件事,并说,这意味着用户取消了请求。我不知道这是如何可能的,我不知道如何解决它。
这里是我的代码:
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
NSString *oauth_nonce = [self genRandStringLength:32];
NSString *oauth_timestamp = [timeStampObj stringValue];
NSURL *feedURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/request_token"];
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys: @"my key here", @"oauth_consumer_key", oauth_nonce, @"oauth_nonce", @"HMAC-SHA1", @"oauth_signature_method", oauth_timestamp, @"oauth_timestamp", @"1.0", @"oauth_version", @"reverse_auth", @"x_auth_mode", nil];
SLRequest *twitterFeed = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:feedURL parameters:parameters];
twitterFeed.account = self.userAccount;
// Making the request
[twitterFeed performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we reached the reate limit
if ([urlResponse statusCode] == 429) {
NSLog(@"Rate limit reached");
return;
}
// Check if there was an error
if (error) {
NSLog(@"The Error is: %@", error.localizedDescription);
return;
}
// Check if there is some response data
if (responseData) {
NSLog(@"%@", responseData);
}
});
}];
必须有一些简单的我失踪了,这是保持我未能完成的一个项目。任何帮助将是伟大的,谢谢!
更具体地说,这个错误代码是用户取消了认证。这很可能是因为首次尝试身份验证失败,因此系统决定取消身份验证,而不是重试。 'urlResponse'有什么有趣的地方? –
输出时只显示:任何想法如何针指出问题?感谢您的回复 –
如果这有什么不同,当我通过添加/测试来改变请求url时,我确实得到了一个响应。这当然是错误的,因为URL是无效的,但它按照它应该的方式运行代码。将其切换回站点URL,并得到相同的错误。这可能与我应该设置的参数有关吗?这真令人沮丧! –