![](/img/trans.png)
[英]I have integrated google plus in my IOS App , Now how can i get profile detail of logged in user?
[英]I have integrated google plus in my IOS App ,But I am not able to get email Id of current user that is logged In
我已經在我的ios應用程序中集成了google plus,我能夠成功登錄,但無法獲取登錄的當前用戶的電子郵件ID。我已引用https://developers.google.com/+/ mobile / ios /,並已按照登錄所需的所有步驟進行操作!
那么,我如何獲得當前的用戶郵件ID,即Google Plus中的Login?
轉到dic中的GTMOAuth2Authentication.m文件方法setKeysForResponseDictionary(該方法在dic中返回訪問令牌)。
accessTocken = [dict valueForKey:@"access_token"]; // access tocken pass in .pch file
[accessTocken retain];
並在您的控制器中
- (IBAction)momentButton:(id)sender {
NSString *str = [NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",accessTocken];
NSString* escapedUrl = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",escapedUrl]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:url usedEncoding:nil error:nil];
NSMutableDictionary *proDic = [[NSMutableDictionary alloc] init];
proDic=[jsonData JSONValue];
NSLog(@"%@",proDic);
這是獲取當前已登錄用戶的電子郵件ID的最簡單方法
首先創建GPPSignIn類的實例變量
GPPSignIn *signIn;
然后在viewDidLoad
初始化它
- (void)viewDidLoad
{
[super viewDidLoad];
static NSString * const kClientID = @"your client id";
signIn = [GPPSignIn sharedInstance];
signIn.clientID= kClientID;
signIn.scopes= [NSArray arrayWithObjects:kGTLAuthScopePlusLogin, nil];
signIn.shouldFetchGoogleUserID=YES;
signIn.shouldFetchGoogleUserEmail=YES;
signIn.delegate=self;
}
接下來在您的視圖控制器中實現GPPSignInDelegate
在這里您可以獲得登錄用戶的電子郵件ID
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error
{
NSLog(@"Received Access Token:%@",auth);
NSLog(@"user google user id %@",signIn.userEmail); //logged in user's email id
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.