通过httpClient.POST
方法,我总是得到-1作为响应,您不知道为什么吗?如果我尝试过帐到另一个端点(不是Google API),那么一切都会很好。
void sendMeasuredData() {
Serial << "Sending data to Google Sheets" <<endl;
StaticJsonBuffer<250> JSONBuffer;
JsonObject& JSONencoder = JSONBuffer.createObject();
JSONencoder["range"] = "Measurements!A1:C1";
JSONencoder["majorDimension"] = "ROWS";
JsonArray& values = JSONencoder.createNestedArray("values"); //JSON array
values.add("TIMESTAMP"); //Add value to array
values.add(temperature); //Add value to array
values.add(humidity); //Add value to array
char JSONmessageBuffer[250];
JSONencoder.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
Serial << JSONmessageBuffer << endl;
HTTPClient httpClient;
httpClient.begin("https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/Measurements!A1:C1:append?valueInputOption=USER_ENTERED","F9:C3:81:B3:84:13:E8:94:87:B1:87:6D:8A:15:75:27:09:56:93:BE");
httpClient.addHeader("Content-Type", "application/json");
httpClient.addHeader("Authorization", "Bearer "+access_token);
int httpCode = httpClient.POST(JSONmessageBuffer);
String payload = httpClient.getString();
Serial << "GoogleSheets Response: " << httpCode << endl;
Serial << payload << endl;
httpClient.end();
}