Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google使用firebase登录iOS时出现400错误_Ios_Objective C_Firebase_Firebase Authentication_Google Signin - Fatal编程技术网

Google使用firebase登录iOS时出现400错误

Google使用firebase登录iOS时出现400错误,ios,objective-c,firebase,firebase-authentication,google-signin,Ios,Objective C,Firebase,Firebase Authentication,Google Signin,我正在尝试为iOS实现Google登录,我按照上面提到的所有步骤设置Google登录,但是当我得到GIDSignInDelegate回调时 - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error 我得到HTTP错误代码为400,用户对象为nil,描述为 Error data: { error = "invalid_grant"; "

我正在尝试为iOS实现Google登录,我按照上面提到的所有步骤设置Google登录,但是当我得到
GIDSignInDelegate
回调时

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error 
我得到HTTP错误代码为400,用户对象为
nil
,描述为

Error data:
{
    error = "invalid_grant";
    "error_description" = "verifier does not match.";
}
我的代码非常简单,只实现了一个Google登录按钮,我的视图控制器实现了GIDSignInDelegate

演示代码:

In AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [FIRApp configure];
    [GIDSignIn sharedInstance].clientID = [FIRApp defaultApp].options.clientID;

    PBLoginSignupUserViewController *loginSignupVC = [[PBLoginSignupUserViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginSignupVC];
    self.window.rootViewController = navController;
    return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

In MyViewController.m <GIDSignInUIDelegate, GIDSignInDelegate>

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
    // GETTING ERROR HERE, AND nil AS USER OBJECT

    if(!error){
        GIDAuthentication *authentication = user.authentication;
        FIRAuthCredential *credential = [FIRGoogleAuthProvider credentialWithIDToken:authentication.idToken
                                                                         accessToken:authentication.accessToken];
    } else {
        // show toast for error
    }
}
AppDelegate.m中的

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
[FIRApp配置];
[GIDSignIn sharedInstance].clientID=[FIRApp defaultApp].options.clientID;
PBLoginSignupUserViewController*loginSignupVC=[[PBLoginSignupUserViewController alloc]init];
UINavigationController*navController=[[UINavigationController alloc]initWithRootViewController:loginSignupVC];
self.window.rootViewController=navController;
返回YES;
}
-(BOOL)应用程序:(UIApplication*)应用程序openURL:(NSURL*)url选项:(NSDictionary*)选项{
return[[GIDSignIn sharedInstance]handleURL:url源应用程序:选项[UIApplicationOpenUrlOptions源应用程序键]注释:选项[UIApplicationOpenUrlOptions注释键];
}
在MyViewController.m中
-(void)signIn:(GIDSignIn*)signIn didSignInForUser:(gidsgoogleuser*)user withError:(NSError*)错误{
//此处获取错误,并将nil作为用户对象
如果(!错误){
GIDAuthentication*authentication=user.authentication;
FIRAuthCredential*credential=[FIRGoogleAuthProvider credentialWithIDToken:authentication.idToken
accessToken:authentication.accessToken];
}否则{
//为错误显示toast
}
}

您是否启用了谷歌登录服务并在您的项目中添加/更新了配置文件some[google service info.plist]。@nikdange\u me是的,我已经配置了所有这些。我曾经遇到过同样的问题,这是一个配置问题。您应该再次尝试重新配置设置,我们有时“可能”会错过步骤。@nikdange_me我用一个新的单视图应用程序尝试过,步骤非常简单,我想没有什么可错过的。如果你有任何线索,请告诉我。谢谢。我试图搜索“无效授权”错误,它与OAuth2服务有关。我只是想帮助你,这可能不是解决方案。你是否启用了谷歌登录服务并在你的项目中添加/更新了一些配置文件[google service info.plist]。@nikdange_me是的,我已经配置了所有这些。我曾经遇到过同样的问题,这是一个配置问题。您应该再次尝试重新配置设置,我们有时“可能”会错过步骤。@nikdange_me我用一个新的单视图应用程序尝试过,步骤非常简单,我想没有什么可错过的。如果你有任何线索,请告诉我。谢谢。我试图搜索“无效授权”错误,它与OAuth2服务有关。我只是想帮你,这可能不是解决办法。