gpt4 book ai didi

ios - 如何从谷歌获取UserID plus Oauth2.0 for IOS

转载 作者:行者123 更新时间:2023-11-29 01:44:41 26 4
gpt4 key购买 nike

我使用了 Google Developers Documentation,但我无法获取 UserID

这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0f/255.0f green:102.0f/255.0f blue:204.0f/255.0f alpha:100.0];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

signIn = [GPPSignIn sharedInstance];

//您之前在“初始化 Google+ 客户端”步骤中设置了 kClientId

    signIn.clientID = kClientId;
[signIn setScopes:[NSArray arrayWithObject: @"https://www.googleapis.com/auth/plus.me"]];

//取消注释以获取用户的电子邮件

     signIn.shouldFetchGoogleUserEmail = YES;

//取消注释获取用户ID

     signIn.shouldFetchGoogleUserID = YES;
signIn.delegate = self;

Gplusbtn = [[GPPSignInButton alloc] init];
Gplusbtn.frame = CGRectMake([simod CG:10], [simod CG:125], [simod CG:300], [simod CG:30]);
Gplusbtn.style=kGPPSignInButtonStyleWide;
Gplusbtn.enabled = YES;
[self.view addSubview:Gplusbtn];
}


- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error) {
_signInAuthStatus.text =
[NSString stringWithFormat:@"Status: Authentication error: %@", error];
return;
}
NSLog(@"ID:%@", signIn.userID);
}

NSLog 显示 ID:(null)

那么代码哪里出了问题,怎么解决呢?

最佳答案

你只需要使用

[GPPSignIn sharedInstance]

像这样:

NSString * gpUserID = [GPPSignIn sharedInstance].userID;

关于ios - 如何从谷歌获取UserID plus Oauth2.0 for IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com