如何在Google plus与iOS集成中获取用户信息
嗨,我正在集成google plus集成,我想获取当前登录的用户信息。我可以在登录后获取令牌,但我不知道如何获取个人信息。 我正在一步一步地登录,因为这只是因为我想在不打开外部浏览器的情况下登录 在UIWebView中打开url链接,该链接在视图中打开登录屏幕并加载如何在Google plus与iOS集成中获取用户信息,ios,objective-c,xcode,uiwebview,google-plus,Ios,Objective C,Xcode,Uiwebview,Google Plus,嗨,我正在集成google plus集成,我想获取当前登录的用户信息。我可以在登录后获取令牌,但我不知道如何获取个人信息。 我正在一步一步地登录,因为这只是因为我想在不打开外部浏览器的情况下登录 在UIWebView中打开url链接,该链接在视图中打开登录屏幕并加载 UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; webView.tag=99; NSString *url =
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webView.tag=99;
NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%@&redirect_uri=%@&scope=%@&data-requestvisibleactions=%@",[GPPSignIn sharedInstance].clientID,callbakc,scope,visibleactions];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
[self.view addSubview:webView];
获取令牌登录的调用
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
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];
NSLog(@"verifier %@",verifier);
break;
}
}
if (verifier) {
NSString *data = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,[GPPSignIn sharedInstance].clientID,secret,callbakc];
NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/token"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
receivedData = [[NSMutableData alloc] init];
} else {
// ERROR!
}
[webView removeFromSuperview];
return NO;
}
我在收到数据后得到了回应
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
NSLog(@"verifier %@",receivedData);}
现在,在令牌之后,我想呼叫获取登录用户信息,请指导我如何实现这一目标,这对我来说将是巨大的。
谢谢。请查看[ios google plus integration][1][1]的答案:@user3874146您有解决方案吗?请让我知道。。我也有同样的问题。