Godot Version
4.3
Question
I’m making a mobile game that sends HTTP requests to the gemini API.
Everything works fine in the engine, and even on remote debug. But when I export the project and install it on my phone (Android. The same one that I use for the remote debug), the HTTP request just seems to stop working.
I get response code ‘0’, result ‘3’ and ‘[_]’ for headers.
The relevant code is displayed below. Note: generate_sentence() is called from another scene.
extends Node
const KEY = preload("res://credentials.json").data.Key
const url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=" + KEY
var response_str: String
signal requestCompleted
@onready var http_request: HTTPRequest = $HTTPRequest
func _on_http_request_request_completed(result, response_code, headers, body):
if response_code == 200:
response_str = parse_gemini_response(body)
requestCompleted.emit()
return
response_str = "Error:" + str(response_code) + " " + str(result) + " " + str(headers)
requestCompleted.emit()
func generate_content(prompt):
var headers = ["Content-Type: application/json"]
var request_data = {
"contents": [{
"parts":[{
"text": prompt
}]
}]
}
http_request.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(request_data))
func parse_gemini_response(body):
var response_string = JSON.parse_string(body.get_string_from_utf8())
var content = response_string['candidates'][0]['content']['parts'][0]['text']
return content
func generate_sentence(prompt: String, display_node: RichTextLabel):
display_node.text = "sending..."
generate_content(prompt)
await requestCompleted
display_node.text = response_str
Could this be an export error? I’m using the default settings for android.
If not, how do I even start to debug this? Is there a way to see the network history like on web? The fact that the remote debug just works normally also doesn’t help.