从iOS设备到google应用程序引擎的Oauth用户身份验证
我正在开发一个iOS应用程序,需要将数据获取/放入我正在开发的google app engine服务器应用程序。iOS应用程序的每个用户都将使用其google身份访问应用程序的服务器部分。我在试着用漂亮的。我已经使用谷歌的服务来获取我的OAuth消费者密钥和OAuth消费者机密 当我为用户创建访问谷歌联系人列表的代码时,它工作正常,但我无法让它在我的应用程序引擎应用程序上工作。尝试时,在authentication controller视图中出现错误“您请求的服务尚不可用。请在30秒后重试”。在appengine控制台中,我看到对/_ah/OAuthGetAccessToken的请求失败(我没有在该路径中提供任何内容) 这是我的密码:从iOS设备到google应用程序引擎的Oauth用户身份验证,ios,google-app-engine,oauth,Ios,Google App Engine,Oauth,我正在开发一个iOS应用程序,需要将数据获取/放入我正在开发的google app engine服务器应用程序。iOS应用程序的每个用户都将使用其google身份访问应用程序的服务器部分。我在试着用漂亮的。我已经使用谷歌的服务来获取我的OAuth消费者密钥和OAuth消费者机密 当我为用户创建访问谷歌联系人列表的代码时,它工作正常,但我无法让它在我的应用程序引擎应用程序上工作。尝试时,在authentication controller视图中出现错误“您请求的服务尚不可用。请在30秒后重试”。在
-(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;
}
我是否使用了正确的URL?范围正确吗?什么会导致该消息?我看到代码中有两个错误和缺少的方法调用:
首先,这个url是错误的:
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"];
它应该指向这一点:
NSURL *authorizeURL = [NSURL URLWithString:@"https://mysite.appspot.com/_ah/OAuthAuthorizeToken"];
最后,在myCustomAuth方法的末尾和返回之前添加以下代码行:
[auth setCallback:@"http://mysite.appspot.com/_my_callback"];
最后一部分回调url指向何处并不重要,因为它不会加载到iOS设备的safari浏览器上。
希望这对您有所帮助:)