2011-12-23 22 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ライブラリが行います。