0 votes

Hi, I am trying to implement something similar to this but in Godot.
It just sends player responses to a google form.


I've managed to connect with the web site and make the request. But for some reason it is not submiting the respose.

This is what I've got so far:

func _send_data():
    var err = 0
    var http = HTTPClient.new() # Create the Client.

    err = http.connect_to_host("docs.google.com", 80) # Connect to host/port.
    assert(err == OK) # Make sure connection was OK.
    print (err)

    # Wait until resolved and connected.
    while http.get_status() == HTTPClient.STATUS_CONNECTING or http.get_status() == HTTPClient.STATUS_RESOLVING:
    print (http.get_status())
    assert(http.get_status() == HTTPClient.STATUS_CONNECTED) # Could not connect  

    var header = ["entry.986078935", "Content-Type: application/json"]
    var field = JSON.print(str(user_melody))
    var result = http.request(http.METHOD_POST, "/forms/d/e/1FAIpQLSe8Z91NGAN-ssDJbMSOuZtM7eWZQvt8mWoMxuJ79HtM-f4Qkg/formResponse", header, field)

    # Keep polling until the request is going on
    while (http.get_status() == HTTPClient.STATUS_REQUESTING):
    # Make sure request finished
    print (http.get_status())
    assert(http.get_status() == HTTPClient.STATUS_BODY or http.get_status() == HTTPClient.STATUS_CONNECTED)

The debug Output prints:


Not sure what is going on... If you have any clue, please let me know!

in Engine by (24 points)

I want to do the same thing but with sheets will it work directly or I need to use google forms first, as you did?

1 Answer

0 votes
Best answer

I figured it out!
I am sharing the answer in case someone needs it.
I created a HTTPRequest Node and added a script there with this code:

extends HTTPRequest

var my_full_url = "https://docs.google.com/forms/d/e/****INSERT_YOUR_FORM_URL_HERE****/formResponse"
    var my_data = {"entry.###WHATEVER YOUR ENTRY KEY IS###" : "***ADD YOUR RESPONSE HERE***"}
    var headers = ["Content-Type: application/x-www-form-urlencoded"]
    var http = HTTPClient.new()

    func _ready() -> void:

    func send_data():
        # Transform data so it can be sent:
        var headers_pool = PoolStringArray(headers)
        var my_data_ready = http.query_string_from_dict(my_data)
        #Send data!!!!
        var result = self.request(my_full_url, headers_pool, false, http.METHOD_POST, my_data_ready)
by (24 points)

Hello, Mentuhetep, i have the same problem with you. i want a player to fill some responses via godot game and then send them to a google form i've created. I have linked the form with a spreadsheet.

I used your script. In the debuger screnn i printed out the result variable and is zero (0). So based to godot documentation the connection of the http request was completed right. But in google spreadsheet i cannot see any response.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.