gpt4 book ai didi

firebase - 使用 firebase Rest Api 使用电子邮件和密码注册用户

转载 作者:行者123 更新时间:2023-12-04 13:36:24 28 4
gpt4 key购买 nike

我正在创建一个项目,用户需要能够登录到他们的帐户并查看一些数据。我正在创建一个统一的 Windows 应用程序,所以根据我从研究中的理解,我必须使用 firebase RestAPI,而不是 SDK。我设法使用了实时数据库,但我在身份验证方面遇到了困难。

我关注了 this教程并使用了 documentation用于使用 RestAPI 将用户注册到 firebase。我不断收到 400(错误请求)错误。我找到了这个 post ,解决方案是使用强密码,但这不起作用。

由于我使用不太可靠的统一 c# 包作为客户端,因此我也使用 nodeJs 测试了我的代码。同样的错误。

我的代码:

C#

private void SignUpUser(string email, string username, string password)
{
string userData = "{\"email\":\"" + email + "\",\"password\":\"" + password + "\",\"returnSecureToken\":true}";
// Content type is json by default
RestClient.Post<SignResponse>("https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=" + AuthKey, userData).Then(
response =>
{
Debug.Log("Success");
}).Catch(error =>
{
Debug.Log(error);
});
}

Javascript

const axios = require("axios");

axios
.post(
'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=' + API_KEY,
{
email: "myEmddail@example",
password: "superStrongzi344##",
returnSecureToken: true,
},
{
'Content-Type': 'application/json',
}
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

部分回复:
response:
{ status: 400,
statusText: 'Bad Request',
headers:
{ expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
pragma: 'no-cache',
date: 'Sun, 10 May 2020 21:09:52 GMT',
'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
vary: 'X-Origin, Referer, Origin,Accept-Encoding',
'content-type': 'application/json; charset=UTF-8',
server: 'ESF',
'x-xss-protection': '0',
'x-frame-options': 'SAMEORIGIN',
'x-content-type-options': 'nosniff',
'alt-svc':
'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"', 'accept-ranges': 'none',
connection: 'close',
'transfer-encoding': 'chunked' },
config:
{ url:
'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY',
method: 'post',
data:
'{"email":"myEmddail@example","password":"superStrongzi344##","returnSecureToken":true}',


有什么我想念的吗?

谢谢

最佳答案

尝试在您的 Firebase 控制台中启用使用电子邮件注册。此外,您使用的 c# 库似乎不太可靠,可能不太适合错误处理,我建议使用内置的 native System.net.http 库。请求的示例:

using System.Net.Http;
private static readonly HttpClient client = new HttpClient();

var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};

var content = new FormUrlEncodedContent(values);

var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);

var responseString = await response.Content.ReadAsStringAsync();

关于firebase - 使用 firebase Rest Api 使用电子邮件和密码注册用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61718706/

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