ios – Google Plus登录

场景:通过Google登录登录到应用程序

执行:

- (void)viewDidLoad {
    [super viewDidLoad];

    GPPSignIn *aGPSSignIn = [GPPSignIn sharedInstance];
    aGPSSignIn.scopes = @[ kGTLAuthScopePlusLogin,kGTLAuthScopePlusUserinfoEmail,kGTLAuthScopePlusUserinfoProfile,kGTLAuthScopePlusMe];
    aGPSSignIn.shouldFetchGoogleUserEmail = YES;
    aGPSSignIn.shouldFetchGooglePlusUser =YES;
    aGPSSignIn.homeServerClientID = kClientID;
    aGPSSignIn.clientID = kClientID;
    aGPSSignIn.delegate = self;
    if (![aGPSSignIn trySilentAuthentication]) {
        [self showLoginButton];
    }
}

- (void)showLoginButton {
    if (!self.signInButton) {        
        self.signInButton = [GPPSignInButton buttonWithType:UIButtonTypeCustom];
        [self.signInButton setFrame:CGRectMake(60,100,200,40)];
    }
    [self.view addSubview:self.signInButton];
}

#pragma mark - GPPSignInDelegate

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error {
    NSString *anAccessToken = auth.accessToken;
    NSLog(@"googleAccessToken:%@",anAccessToken);
}

- (void)didDisconnectWithError:(NSError *)iError {
    if (iError) {
        NSLog(@"Error:%@",iError);
    }
}

注意: – (BOOL)应用程序:(UIApplication *)应用程序openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication注释:(id)注释在AppDelegate中处理.

问题:

>当用户点击Google SignIn按钮并导航到Safari时,Google登录状态很好.在我的应用程序中收到有效的AccessToken.
>但是,如果Google应用程序在iPhone上可用,那么用户将被导航到Google应用,但是在登录时不会接收到AccessToken.我得到一个错误.

错误:

Received error Error Domain=com.google.GooglePlusPlatform Code=-1 “The
operation couldn’t be completed. (com.google.HTTPStatus error 400.)”
UserInfo=0x15d95f90 {NSLocalizedDescription=The operation couldn’t be
completed. (com.google.HTTPStatus error 400.)} and auth object (null)

如果有人可以指导我解决这个问题,这将是非常有帮助的.
谢谢.

解决方法

请在项目中设置URL方案.

脚步:

> Login your developer account
>选择你的项目
>选择API&从边栏的auth
>选择凭据
>复制’REDIRECT URIS’和’BUNDLE ID’
> Oen Xcode项目
>选择项目目标
>选择’信息’
>展开网址类型
>将“BUNDLE ID”粘贴到“标识符”区域
>粘贴URL方案区域中的’REDIRECT URIS’

如果它不工作,尝试用’BUNDLE ID’替换’REDIRECT URIS’,即标识符和URL方案是一样的.

希望这可以帮助你

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...