You can use the code below to access Google+ using Webview:
Initialize UIWebview:
NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%@&redirect_uri=%@&scope=%@",client_id,callbakc,scope]; UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; [webView setDelegate:self]; [self.view addSubview:webView]; [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
Implementation of delegate methods:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { // [indicator startAnimating]; if ([[[request URL] host] isEqualToString:@"localhost"]) { // Extract oauth_verifier from URL query NSString* verifier = nil; NSArray* urlParams = [[[request URL] query] componentsSeparatedByString:@"&"]; for (NSString* param in urlParams) { NSArray* keyValue = [param componentsSeparatedByString:@"="]; NSString* key = [keyValue objectAtIndex:0]; if ([key isEqualToString:@"code"]) { verifier = [keyValue objectAtIndex:1]; break; } } if (verifier) { NSString *authToken = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,client_id,secret,callbakc]; //Use Token to Login } else { // ERROR! } [webView removeFromSuperview]; webView = nil; return NO; } return YES;
}
source share