【问题标题】:Fatal error: Uncaught GuzzleHttp\Exception\ClientException致命错误:未捕获的 GuzzleHttp\Exception\ClientException
【发布时间】:2021-11-14 18:54:31
【问题描述】:

我正在使用 PHP kreait/firebase-php 开发 Firebase Admin SDK,它在实时数据库上运行良好。但是,我要创建用户的身份验证给了我致命错误,它说:致命错误:未捕获的 GuzzleHttp\Exception\ClientException:客户端错误:POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser 导致400 Bad Request

而且我没有足够的经验知道如何解决这个问题。这是我的 PHP 代码,希望对您有所帮助。

<?php

require __DIR__.'/vendor/autoload.php';


use Kreait\Firebase\Factory;
use Kreait\Firebase\Auth;

$factory = (new Factory)
    ->withServiceAccount('dazsma-test-firebase-adminsdk-xprg4-0bedd1e1e2.json')
    ->withDatabaseUri('https://dazsma-test-default-rtdb.asia-southeast1.firebasedatabase.app/');
    
    $database = $factory->createDatabase();
    $auth = $factory->createAuth();


    
?>

第二个

<?php
session_start();
include('dbcon.php');

if(isset($_POST['register_btn']))
{
    $fullname = $_POST['full_name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $password = $_POST['password'];

    $userProperties = [
        'email' => $email,
        'emailVerified' => false,
        'phoneNumber' => '+09'.$phone,
        'password' => $password,
        'displayName' => $fullname,
    ];
    
    $createdUser = $auth->createUser($userProperties);

    if($createdUser) 
    {
        $_SESSION['status'] = "User Created Successfully!";
        header('Location: register.php');
        exit();
    }
    else 
    {
        $_SESSION['status'] = "User Creation Failed!";
        header('Location: register.php');
        exit();
    }

}

这是我的 register.php

<?php 
session_start();
include('includes/header.php');
?>

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-6">

        <?php 
                if(isset($_SESSION['status'])) {
                    echo "<h5 class='alert alert-success'>".$_SESSION['status']."</h5>";
                    unset($_SESSION['status']);
                }
            ?>
            <div class="card">
                <div class="card-header">
                    <h4>
                        Create User
                        <a href="index.php" class="btn btn-danger float-end"> Back</a>
                    </h4>
                </div>
                <div class="card-body">

                <form action="code.php" method="POST">

                    <div class="form-group mb-3">
                        <label for="">Full Name</label>
                        <input type="text" name="full_name" class="form-control">
                    </div>
                    <div class="form-group mb-3">
                        <label for="">Email Address</label>
                        <input type="email" name="email" class="form-control">
                    </div>
                    <div class="form-group mb-3">
                        <label for="">Phone Number</label>
                        <input type="number" name="phone" class="form-control">
                    </div>
                    <div class="form-group mb-3">
                        <label for="">Password</label>
                        <input type="password" name="password" class="form-control">
                    </div>
                    <div class="form-group mb-3">
                        <button type="submit" name="register_btn" class="btn btn-primary">Register</button>
                    </div>

                </form>

                    
                </div>
            </div>
        </div>
    </div>
</div>

<?php 
include('includes/footer.php');
?>

**Please help, I'm in a rush.**

【问题讨论】:

    标签: php firebase guzzle


    【解决方案1】:

    文档中有一个关于错误处理的部分:

    https://firebase-php.readthedocs.io/en/5.x/troubleshooting.html#error-handling

    在不知道您使用表单提交的输入的情况下,我看到以下可能的原因:

    • 密码太短
    • 电子邮件无效
    • 电话号码无效

    捕捉异常并检查它应该会给你真正的原因。

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多