2012-03-04 55 views
-1

我正在开发一个iOS应用,需要将数据发送到我正在开发的谷歌应用引擎服务器应用。 iOS应用程序的每个用户都将使用他们的Google身份访问应用程序的服务器部分。我正在尝试使用漂亮的gtm-oauth library。为了获得我的OAuth使用者密钥和OAuth消费者密钥,我使用了Google的服务register my domain从iOS设备到谷歌应用引擎的Oauth用户认证

当我创建用于访问Google联系人列表的代码时,它可以正常工作,但我无法使其与我的应用程序引擎应用程序协同工作。当我尝试时,在验证控制器视图中出现错误“您请求的服务尚未可用,请在30秒内再试一次”。在应用引擎控制台中,我看到/ _ah/OAuthGetAccessToken失败的请求(我没有提供任何此路径)。

这里是我的代码:我使用的是正确的网址

-(IBAction)authButtonClicked: (id) sender { 
    [GTMHTTPFetcher setLoggingEnabled:YES]; 
    NSURL *requestURL = [NSURL URLWithString:@"https://mysite.appspot.com/_ah/OAuthGetRequestToken"]; 
    NSURL *accessURL = [NSURL URLWithString:@"https:/mysite.appspot.com/_ah/OAuthAuthorizeToken"]; 
    NSURL *authorizeURL = [NSURL URLWithString:@"https://mysite.appspot.com/_ah/OAuthGetAccessToken"]; 
    NSString *scope = @"http://mysite.appspot.com/"; 
    GTMOAuthAuthentication *auth = [self myCustomAuth]; 
    GTMOAuthViewControllerTouch *viewController; 
    viewController = [[GTMOAuthViewControllerTouch alloc] initWithScope:scope 
                  language:nil 
                requestTokenURL:requestURL 
                authorizeTokenURL:authorizeURL 
                 accessTokenURL:accessURL 
                 authentication:auth 
                   appServiceName:@"My Service" 
                   delegate:self 
                 finishedSelector:@selector(viewController:finishedWithAuth:error:)]; 
    [[self navigationController] pushViewController:viewController animated:YES]; 
} 

- (GTMOAuthAuthentication *)myCustomAuth { 
    NSString *myConsumerKey = @"mysite.appspot.com"; // from google registration 
    NSString *myConsumerSecret = @"xxxxxxxxxxxxxxx"; // from google registration 
    GTMOAuthAuthentication *auth; 
    auth = [[GTMOAuthAuthentication alloc]    initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 
                 consumerKey:myConsumerKey 
                 privateKey:myConsumerSecret]; 
    auth.serviceProvider = @"Custom Auth Service"; 
    return auth; 
} 

是谁?范围是否正确?什么会导致该消息?

回答

0

我看到一对夫妇的错误代码,而遗漏的方法调用:
首先,这个网址是错误的:

NSURL *accessURL = [NSURL URLWithString:@"https:/mysite.appspot.com/_ah/OAuthAuthorizeToken"]; 

应该不是指向:

NSURL *accessURL = [NSURL URLWithString:@"https://mysite.appspot.com/_ah/OAuthGetAccessToken"]; 

二,这个URL也是错误的:

NSURL *authorizeURL = [NSURL URLWithString:@"https://mysite.appspot.com/_ah/OAuthGetAccessToken"]; 

它肩d点这一个,而不是:

NSURL *authorizeURL = [NSURL URLWithString:@"https://mysite.appspot.com/_ah/OAuthAuthorizeToken"]; 

终于在myCustomAuth方法结束之前返回的添加这行代码:

[auth setCallback:@"http://mysite.appspot.com/_my_callback"]; 

不要紧,给你点这里回调网址的最后部分,因为它不会在iOS设备的Safari浏览器中加载。
希望对你有所帮助:)

相关问题