iOS:使用谷歌登录

标签 ios objective-c iphone xcode google-signin

我正在尝试使用 Google 登录。它适用于所有帐户。但是行为是不同的。对于某些帐户,它会发送完整的公开资料,即显示名称、性别、电子邮件地址、用户 ID 等。

对于某些(新)帐户,它只是发送电子邮件地址和用户 ID DisplayName,而性别为零。每次使用 Google 登录时,我都需要所有这些参数。为什么某些帐户缺少这些参数?

最佳答案

请关注这个link

当 Google 登录过程完成后输入此代码

-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
    {
        if (error)
        {
            // Do some error handling here.
        }
        else
        {
            GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"];
            query.fields = @"id,emails,image,name,displayName";
            GTLServicePlus* plusService = [[GTLServicePlus alloc] init] ;
            plusService.retryEnabled = YES;
            [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
            plusService.apiVersion = @"v1";
            [plusService executeQuery:query  completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
            {
                if (!error)
                {
                    NSLog(@"Display name : %@",[person.name.givenName stringByAppendingFormat:@" %@", person.name.familyName]);
                    NSLog(@"email id : %@",[GPPSignIn sharedInstance].authentication.userEmail);
                }
            }];
        }
    }

希望此链接和代码对您有用。

关于iOS:使用谷歌登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33390447/

相关文章:

java - 等效于 Objective C/Swift 的 Java ThreadLocal 变量

ios - Xcode:libpods.a 是红色的

ios - 不添加 LSApplicationQueriesSchemes 的 CanOpenURL

ios - Xcode 4.2.1 : NSThread causing memory leak, 使用 ARC

ios - 调整 UITableViewCell 内容的大小

ios - 如何检测 iPhone 屏幕的右侧或左侧是否有轻按?

iphone - 如何加载存储在静态库中的图像

ios - 如何从 ARKit 中的节点动画到实际 View

ios - Objective-C - 从两个字符串创建 NSDate

带指针的 Objective-C 转换