【发布时间】:2012-03-16 08:39:25
【问题描述】:
我正在开发一个 iOS 应用程序,该应用程序需要将数据获取/放入我也在开发的谷歌应用引擎服务器应用程序。 iOS 应用程序的每个用户都将使用他们的谷歌身份来访问应用程序的服务器部分。我正在尝试使用漂亮的gtm-oauth library。我已使用 Google 的服务 register my domain 来获取我的 OAuth 消费者密钥和 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;
}
我使用的网址是否正确?范围是否正确?什么会导致该消息?
【问题讨论】:
标签: ios google-app-engine oauth