firebase auth rest api 未在 arduino ide 中返回全身响应 [英] firebase auth rest api not returning the full body response in arduino ide
问题描述
我在 arduino ide 中遇到了 firebase auth rest api 的问题,以下代码返回代码 200
i've been stuck in a problem with firebase auth rest api in arduino ide, the following code returns code 200
String url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + String(apiKey);
http.setTimeout(5000);
http.begin(url);
http.addHeader("Content-Type", "application/json");
String dataSent = "{\"email\":\"" + String(email) + "\",\"password\":\"" + String(pswd) + "\",\"returSecureToken\":\"true\"}";
int status = http.POST(dataSent);
Serial.println(status);
if (status <= 0)
{
Serial.printf("HTTP error: %s\n",
http.errorToString(status).c_str());
return false;
}
// Read the response.
String payload = http.getString();
Serial.println(payload);
但是当我查看串行监视器时,响应如下所示:
but when i look in my serial monitor the response looks like this:
{
kind: "the kind of response",
localId: "someId",
email: "myEmail",
displayName: "myDisplayName",
idToken: "someIdToken",
registered: "someBoolean",
}
witch 显然没问题,但是当我在邮递员中尝试相同的 http 请求时,响应还包括 refreshToken
和 expiresIn
witch aparently is ok but when i try the same http request in postman the response includes also refreshToken
and expiresIn
经过更多调查,我发现 postman 的 localId
大约有 980 个字符,而我的 arduino 代码中的 localId
大约只有 680 个
with even more investigation i found that localId
from postman is about 980 characters while the localId
from my arduino code is only about 680
我正在尝试(但失败)使用 localId 来对 Firestore api 的请求进行身份验证,我认为这种长度差异是困扰我的问题.这真的是问题吗?
im trying (and failing) to use the localId to authenticate a request with the firestore api and i think this difference in lenght is what's been buggingme. could that really be the problem ?
推荐答案
method: "POST",
body: JSON.stringify({
email: enteredEmail,
password: enteredPassword,
returnSecureToken: true,
}),
headers: {
"Content-Type": "application/json",
},
})
注意:确保 {returnSecureToken: true} 是请求正文的一部分
NB: Make sure {returnSecureToken: true} is part of your request body
这篇关于firebase auth rest api 未在 arduino ide 中返回全身响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!