如何在使用Google OAuth 2.0时阻止显示访问代码的额外视图 [英] How to prevent the extra view displaying an access code when using Google OAuth 2.0
问题描述
我按照 http:// googlemac。 blogspot.com/2011/05/ios-and-mac-sign-in-controllers.html 允许用户使用Google登录iPhone应用程序。点击允许访问按钮后,我会看到一个额外的屏幕,请复制此代码,切换到您的应用程序并将其粘贴到那里:(文本框中的代码)。
I followed http://googlemac.blogspot.com/2011/05/ios-and-mac-sign-in-controllers.html to allow users to use Google to login to an iPhone app. After I tap "Allow access" button I get an extra screen that says, "Please copy this code, switch to your application and paste it there: (code in a textbox)."
这就是我所拥有的:
- (IBAction)googleLoginTapped:(UIButton *)sender
{
[self loginToGoogle];
}
- (void)loginToGoogle
{
// For Google APIs, the scope strings are available
// in the service constant header files.
NSString *scope =@"https://www.googleapis.com/auth/userinfo.profile";
// Typically, applications will hardcode the client ID and client secret
// strings into the source code; they should not be user-editable or visible.
// But for this sample code, they are editable.
NSString *clientID = @"my clientID";
NSString *clientSecret = @"my clientSecret";
// Display the autentication view.
SEL finishedSel = @selector(viewController:finishedWithAuth:error:);
GTMOAuth2ViewControllerTouch *viewController;
viewController = [GTMOAuth2ViewControllerTouch controllerWithScope:scope
clientID:clientID
clientSecret:clientSecret
keychainItemName:nil
delegate:self
finishedSelector:finishedSel];
// For this sample, we'll force English as the display language.
NSDictionary *params = [NSDictionary dictionaryWithObject:@"en"
forKey:@"hl"];
viewController.signIn.additionalAuthorizationParameters = params;
// Optional: display some html briefly before the sign-in page loads
NSString *html = @"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
viewController.initialHTMLString = html;
viewController.signIn.shouldFetchGoogleUserProfile = YES;
[self presentModalViewController:viewController animated:YES];
}
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
if (error != nil)
{
// Authentication failed (perhaps the user denied
请看这个链接是好的 https://developers.google.com/accounts/docs/ OAuth2InstalledApp
推荐答案
我尝试了这种方法,并且工作正常,把它放在你的webViewDidFinishLoad方法中:
I tried this approach, and work fine, put this in your webViewDidFinishLoad method :
if ([webView.request.URL.absoluteString rangeOfString:@"https://accounts.google.com/o/oauth2/approval?"].location != NSNotFound) {
webView.hidden=YES;
}
这篇关于如何在使用Google OAuth 2.0时阻止显示访问代码的额外视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!