[Solved] How do I handle a http post request for google spreadsheets in exe builds?

Hello everybody! :grin:

I’ve tried to implement a leader board for the game Pinkoball.
I used Google Spreadsheets and a http post request (like described in this thread: [solved] How do I create a leaderboard with google spreadsheets and get requests? )
Like the thread told it work’s fine on html5 builds.

In the preview mode it doesn’t get a response. Also the Win export as exe has the problem: the Data isn’t incoming. :thinking:
The http post request is outgoing in every version - so the highscores of the exe build and the preview mode will be pushed to my spreadsheet - but the data is only accessible in the html5 build. (I have text fields, which show the data in the html5 build fine and in all other cases the text fields just say “0”)

So I might have some weird kind of misusing/understanding something, where the more experienced gdev folks can help?

Here is what I’m doing:

  • calling a http post request and save the response in the variable “JSON“
  • parsing the “JSON“ into a variable “JSONString“
  • use javascript to handle all the data in the “JSONString“

Maybe in the javascript part is an error which just don’t make problems on html5? :see_no_evil:
So here is an example, of what I’m doing:

var myObjects=[];
myObjects[0] = runtimeScene.getObjects("number1"); //a text object
myObjects[1] = runtimeScene.getObjects("name1"); //a text object

var inputVariable = runtimeScene.getVariables().get("JSONString");

myObjects[0][0].setString(inputVariable.getChild("name1").getAsString().toString());
myObjects[1][0].setString(inputVariable.getChild("score1").getAsString().toString());

Do you have any suggestions? :shamrock:

@kink i know you have used request in your demo .exe file, did you have trouble or advice ?

1 Like

Hello,

Like this no, i have no idea, maybe if i could see the events, but i never had trouble to access the data. I’ll check my work to see if i did something that i’ve forgot.

1 Like

@OniGiri, can you show us the JSon you are trying to parse ?

1 Like

Hello @Kink and thank you for your time!

Here is my request:

I’m new to the http request stuff. So I had to admit that I tried out different entries until the leader board in the html5 build run fine:

Nothing is red in console ?
CTRL+SHIFT+I in your game or in preview.

1 Like

i took a look on my work on sending requests, try something like this (idk if it works the same way with google script you use):
image

I remember i had trouble by not using strictly domain name for the host, and full path to page like in the screenshot.

1 Like

Thanks for the new information! :smiling_face_with_three_hearts:

@Kink : I’ve change the request like you have shown. For html5 it is working :space_invader:

@Bouh : After changing the request to the given format, I tried what you told me: I’ve opend the console in the preview mode and get this response as warning:
[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

In the “Windows zip folder” build I can’t open the console with the keyboard. But the outcome looks like in the preview game.

So it seems to be a deeper problem? :scream: :sweat_smile:

Complement: in all game variants the score is written to the spreadsheet.

@OniGiri and @Kink i think this can help you when you build your .exe, you can see console like this :
Execute with your game with argument “–remote-debugging-port=8315”
Open on chrome “http://localhost:8315
Click on Link and tadam :slight_smile:

Maybe google ask token or something like authorisation for ask data with API ?

You have a example with GD5 :
https://editor.gdevelop-app.com/?project=example://parse-json-from-api
btw you should fill all fields in parameters, i see Content type is empty, “” is needed.

@Bouh I don’t understand the part with the exe.
But I followed your example and integrated the example into my leader board.
Your example runs fine in the preview mode but mine not.

So I came to the conclusion that it must be something with the answer, which is sended by the google script. (I found the same way on different sites and it works for the html5 version)
Here is an example for the function in the google script:

function doGet() {
  
  var content = {"result" : "success", "myData" : "DataXYZ"}; 
  return ContentService.createTextOutput(JSON.stringify(content)).setMimeType(ContentService.MimeType.JSON);
}

In the preview mode the debugger just shows a “0” for the response variable while the response variable of the star wars example is holding data.

You have your game.exe
create a shortcut, and in properties, in target add
–remote-debugging-port=8315

like this :
C:\Users\Bouh\Desktop\game-windows\Platformer.exe --remote-debugging-port=8315

  • Save and launch the shortcut
  • Open on chrome “http://localhost:8315
  • Click on Link, now you have debugger console of your game.exe

Got it! Thank you for your kind advice! :space_invader:

Is there somebody,
who want to try the google script communication with Gdevelop? :space_invader:

I really hope that more eyes on this will find a solution. :shamrock:

Send me your project in PM i will take a look

1 Like

I have found a solution:

I added a async http request in the javascript part of my code, like described here:

Than I recieve the data from the google script in this javascript block and can work with :shamrock:

3 Likes

Hey, I can’t get my head around this, will please share your solution with screenshots ?
Thanks

They used an async Javascript async request. You can do it with a something like this:

let variable = runtimeScene.getVariables().get("SceneVariableName");

fetch("https://script.google.com/macro/s/balbalabla/exec",{
    method: "POST"
}).then((request) => {
    return response.json();
}).then((response) => {
    gdjs.evtTools.network.jsonToVariableStructure(response, variable);
});