For context, I'm doing a small application in Qt QML that requires reading/writing data into a google sheet. The reading part is working fine, however I'm having trouble using the "sheets.spreadsheets.values.append" function from google sheets API V4 (documentation can be found here : https://developers.google.com/sheets/api/reference/rest/)
The Javascript function below takes this URL as parameter: https://sheets.googleapis.com/v4/spreadsheets/{SHEET-ID}/values/A2:ZZ:append?valueInputOption=RAW&key={API-KEY}
The request body passed as parameter is this one:
{
"majorDimension": "ROWS",
"values": [
[
"15:41 02/08/2019",
"Steven",
"20",
"Male",
"test@mail.com",
"FooBar"
]
]
}
The function that is called to do the POST:
function postReq(url, callback, request = null) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.onload = function (e) {
if (e) console.log(e);
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
callback(xhr.responseText.toString());
} else {
callback(null);
console.log(xhr.status);
}
} else {
console.log(xhr.status);
};
};
xhr.send(request);
};
This always returns a 401 response code which persists even if I publish the sheet to the web and the API key shouldn't be the issue since it works fine when reading data (I made sure the sheet is editable too).