oAuth2在iOS7中检索个人资料电子邮件

时间:2014-12-21 20:23:08

标签: objective-c ios7 oauth-2.0 google-plus

我跟着this tutorial并且能够成功验证并获得访问令牌,现在我很难理解如何在关闭webview并加入我的控制器之前获取与用户配置文件关联的电子邮件。

有什么建议吗?我知道谷歌有这方面的SDK,但如果我的要求可以通过我正在使用的教程,我不想走那条路。

if (verifier) {
                NSString *data = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,client_id,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!
            }

           //Should I need to call another HTTP to retrieve email (or) email already available part of any other response?

如果我需要调用另一个HTTP,应该调用哪个URL?

1 个答案:

答案 0 :(得分:3)

people.get API方法进行经过身份验证的请求,userId设置为meperson resource有一个emails数组,type设置为account的电子邮件是经过验证的电子邮件。

相关问题