I am attempting to send an HTTP POST request to the GCM server using Google Apps Script. I have both the device ID and the necessary credentials. Below is the code I am currently using:
function doThat(){
var url = "https://android.googleapis.com/gcm/send";
var options = {
"method": "post",
"headers": {
"Authorization": "key=myAPIKEY",
"Content-Type":"application/json"
},
"payload": {
"data": {
"score": "5x1",
"time": "15:10"
},
"registration_ids": ["regid1"]
}
};
var response = UrlFetchApp.fetch(url, options);
Logger.log("Response: "+response.toString());
}
In the code above, myAPIKEY and regid1 serve as placeholders. A similar Java code functions correctly for this task, indicating that the credentials are not the issue. I referred to this Android documentation link to determine the JSON format required to communicate with the GCM server (Please do not alter the API keys and other information in the code below as they are directly sourced from the link on the Android GCM site):
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
"registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],
"data" : {
...
},
}
It's worth noting that I consistently receive an "Error=Missing Registration" message at the Logger.log() statement in the execution logs. The Java equivalent code performs flawlessly, while the Google Script encounters this error. What could be the issue here?