【问题标题】:OAuth access token request failing (NSErrorFailingURLStringKey)OAuth 访问令牌请求失败 (NSErrorFailingURLStringKey)
【发布时间】:2011-06-22 08:51:53
【问题描述】:

我在 OAuth 过程中完成了以下步骤:
1) 请求令牌
2) 授权令牌
3) 接收 PIN 码

我无法使用收到的 PIN 获取访问令牌。它总是点击我的accessTokenTicket:didFailWithError 选择器。

这是传递给它的 URL:
http://www.formspring.me/oauth/access_token?oauth_token=TOKEN_KEY_HERE&oauth_verifier=PIN_HERE

这是被调用的代码:

- (void)successfulAuthorizationWithPin:(NSString *)pin {
    NSLog(@"successfulAuthorizationWithPin:%@", pin);<br>
    OAMutableURLRequest *request;<br>
    OADataFetcher *fetcher;

    NSURL *url = [NSURL URLWithString:kOAuthAccessTokenURL];

    request = [[[OAMutableURLRequest alloc] initWithURL:url
                                               consumer:self.consumer
                                                  token:self.accessToken
                                                  realm:nil
                                      signatureProvider:nil] autorelease];

    OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"oauth_token" value:self.accessToken.key];
    OARequestParameter *p1 = [[OARequestParameter alloc] initWithName:@"oauth_verifier"
                                                                value:pin];

    NSArray *params = [NSArray arrayWithObjects:p0, p1, nil];
    [request setParameters:params];
    [request prepare];

    NSLog(@"%@", request.URL);

    fetcher = [[[OADataFetcher alloc] init] autorelease];

    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(accessTokenTicket:didFinishWithData:)
                  didFailSelector:@selector(accessTokenTicket:didFailWithError:)];

    [p0 release];
    [p1 release];
}

didFail 方法(只是错误的NSLog)会产生这个错误:

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x6160c20 {NSErrorFailingURLKey=http://www.formspring.me/oauth/access_token?oauth_token=TOKEN_KEY_HERE&amp;oauth_verifier=PIN_HERE, NSErrorFailingURLStringKey=http://www.formspring.me/oauth/access_token?oauth_token=TOKEN_KEY_HERE&amp;oauth_verifier=PIN_HERE, NSUnderlyingError=0x61321f0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"}

我的 URL 格式是否错误或提供的参数错误或不足?

谢谢!
约翰

【问题讨论】:

    标签: iphone oauth oauth-2.0 access-token nsurlerrordomain


    【解决方案1】:

    您是否检查过生成的 oauth 令牌是否正确?我建议从那里开始。 Here's 检查您的 OAuth 令牌的好资源。

    如果出现身份验证错误,则会出现该消息。通过 Netflix Oauth 验证生成 URL 并在浏览器上运行。看看它是否加载。

    【讨论】:

      猜你喜欢
      • 2011-01-19
      • 2013-10-22
      • 2019-09-16
      • 2011-03-18
      • 2013-12-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      相关资源
      最近更新 更多