Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Hanna |
I’m trying to use Google’s Firebase REST API to create new accounts in my android application (following Guilherme’s tutorial https://www.youtube.com/watch?v=Udm7uDQM05w). However I cannot get is to work!
Whenever the button for creating a new account is pressed there is a function call to register(email: String, password: String, http: HTTPRequest)
const API_KEY := [API KEY]
const REGISTER_URL := "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=%s" % API_KEY
func register(email: String, password: String, http: HTTPRequest):
var body := {
"email": email,
"password": password,
"returnSecureToken": true,
}
var error = http.request(REGISTER_URL, _get_request_headers(),
false, HTTPClient.METHOD_POST,
to_json(body))
var result := yield(http, "request_completed") as Array
if result[1] == 200:
# Save current token
When the http request is completed _on_HTTPRequest_request_completed(result, response_code, headers, body)
is called.
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
var response_body := JSON.parse(body.get_string_from_ascii())
if response_code != 200:
notification.text = response_body.result.error.message.capitalize()
else:
notification.text = "Welcome!"
yield(get_tree().create_timer(2.0), "timeout")
get_tree().change_scene("res://Scenes/Login/Login.tscn")
The body of the http request is empty and I get and error trying to parse it: JSON.parse(body.get_string_from_ascii())
.
I have tried to use Postman to make requests to their endpoints and it works fine. It also works fine to make requests from Postman to Firebase.
Is there any changes in Godot 3.2 that I need to know about in order to get this to work? Any clues on how to solve this would be greatly appreciated!