2011-12-23 75 views
4

是否有人能夠使用反向身份驗證成功獲取用戶的OAuth令牌?我的應用具有反向驗證權限,但我很難獲取有效的驗證令牌。我正在使用OAuthconsumer,對於如何修改OAuth調用以獲取其他x_auth_mode模式,我有點困惑。Twitter反向驗證iPhone

我不斷收到

Failed to validate oauth signature and token 

任何有識之士將不勝感激,謝謝提前!

回答

0

我發現令人費解的程度seancook例如,該過程似乎要複雜得多,它實際上是。這裏是反向身份驗證的簡單本質:

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庫就行了。