2011-06-28 10 views
1

別のWebサービスに接続するためにiPhoneアプリにOAuthを設定しようとしていますが、問題があります。私のiPhoneアプリケーションでOAuthを使用するには?

google gtm-oauthファイルをダウンロードしてプロジェクトに追加しました。

- (GTMOAuthAuthentication *)myCustomAuth { 
    NSString *myConsumerKey = @"2342343242"; // pre-registered with service 
    NSString *myConsumerSecret = @"324234234242"; // pre-assigned by service 

    GTMOAuthAuthentication *auth; 
    auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 
                 consumerKey:myConsumerKey 
                 privateKey:myConsumerSecret] autorelease]; 

    // setting the service name lets us inspect the auth object later to know 
    // what service it is for 
    auth.serviceProvider = @"RunKeeper"; 

    return auth; 
} 
- (void)signInToCustomService { 

    NSURL *requestURL = [NSURL URLWithString:@"https://runkeeper.com/apps/token"]; 
    NSURL *accessURL = [NSURL URLWithString:@"https://runkeeper.com/apps/token"]; 
    NSURL *authorizeURL = [NSURL URLWithString:@"https://runkeeper.com/apps/authorize"]; 
    NSString *scope = @"http://example.com/scope"; 

    GTMOAuthAuthentication *auth = [self myCustomAuth]; 

    // set the callback URL to which the site should redirect, and for which 
    // the OAuth controller should look to determine when sign-in has 
    // finished or been canceled 
    // 
    // This URL does not need to be for an actual web page 
    [auth setCallback:@"http://www.example.com/OAuthCallback"]; 

    // Display the autentication view 
    GTMOAuthViewControllerTouch *viewController; 
    viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope 
                   language:nil 
                 requestTokenURL:requestURL 
                 authorizeTokenURL:authorizeURL 
                  accessTokenURL:accessURL 
                  authentication:auth 
                  appServiceName:@"RunKeeper" 
                   delegate:self 
                 finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease]; 

    [[self navigationController] pushViewController:viewController 
              animated:YES]; 
} 

これは私がに接続しようとしていますAPIです:http://developer.runkeeper.com/healthgraph/registration-authorization

答えて

2

まず、OAuthの上にお読みください。通常のログイン/ pwタイプの認証とは少し異なります。

第二に、あなたはhttp://code.google.com/p/gtm-oauth/

+0

[OK]をでGoogleのOAuthライブラリを使用することができ、私は、関連するすべてのファイルをダウンロードし、私のプロジェクト内のフォルダにそれらを追加しましたが、今私は何をしますか? – Jon

関連する問題