Send data to Google Forms

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mentuhetep

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 = # Create the Client.

	err = http.connect_to_host("", 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!

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?

Help me please | 2021-07-19 12:13

:bust_in_silhouette: Reply From: Mentuhetep

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 = "****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 =
    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)

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.

takis_17 | 2021-03-24 00:38