【问题标题】:Twitter Reverse Auth iPhoneTwitter 反向验证 iPhone
【发布时间】:2014-10-04 18:12:43
【问题描述】:

是否有人能够使用反向身份验证成功获取用户的 OAuth 令牌?我的应用程序具有反向身份验证权限,但我很难获得有效的身份验证令牌。我正在使用 OAuthconsumer,我对如何修改附加 x_auth_mode 模式的 OAuth 调用有点困惑。

我一直在努力

Failed to validate oauth signature and token

任何见解将不胜感激,在此先感谢!

【问题讨论】:

    标签: api twitter


    【解决方案1】:

    您知道 Sean Cook(Twitter 开发人员)的示例代码吗? https://github.com/seancook/TWiOS5ReverseAuthExample

    他的解决方案很有效,而且比 Twitter 文档更详细... https://dev.twitter.com/docs/ios/using-reverse-auth

    【讨论】:

      【解决方案2】:

      我发现 seanook 示例令人费解,以至于过程看起来比实际复杂得多。以下是反向认证的简单本质:

      NSMutableURLRequest *rq = [TDOAuth URLRequestForPath:@"/oauth/request_token" POSTParameters:@{@"x_auth_mode": @"reverse_auth"}  host:@"api.twitter.com" consumerKey:APIKey consumerSecret:APISecret accessToken:nil tokenSecret:nil];
      
      [NSURLConnection sendAsynchronousRequest:rq queue:nil completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
          id oauth = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
          SLRequest *reverseAuth = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"] parameters:@{
              @"x_reverse_auth_target": APIKey,
              @"x_reverse_auth_parameters": oauth
          }];
          reverseAuth.account = account;
          [reverseAuth performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *urlResponse, NSError *error) {
              id creds = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
              id credsDict = [NSMutableDictionary new];
              for (__strong id pair in [creds componentsSeparatedByString:@"&"]) {
                  pair = [pair componentsSeparatedByString:@"="];
                  credsDict[pair[0]] = pair[1];
              }
              NSLog(@"%@", credsDict);
          }];
      }];
      

      我的示例使用 TDOAuth,但任何 OAuth 库都可以。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-23
        • 2011-03-05
        • 2014-03-22
        • 2012-10-05
        • 1970-01-01
        • 2012-10-24
        • 2014-02-23
        • 1970-01-01
        相关资源
        最近更新 更多