如何发送来自Google Apps脚本的POST数据? [英] How to send POST data coming from Google Apps Script?
问题描述
我使用Firebase Cloud Messaging作为在我的Web应用程序中发送推送通知的方式.所以现在我将Postman用作发送推送通知的方式,但是我只能手动发送
I used Firebase Cloud Messaging as a way to have push notifications in my web app. So now I am using Postman as a way to send my push notifications but i only send it manually
我需要从Google Apps脚本发送推送通知.
From google apps script I need to send my push notification.
这是我在邮递员中使用的,没有问题,并且可以正常工作
This is what I use in Postman which has no problem and it works
这是从我的Google Apps脚本中获得的
This is from my Google apps script
function firebaseNotification() {
var headers = {
"Authorization" : "key=key",
"Content-Type" : "application/json"
};
var options =
{
"notification": {
"title": "CWMS",
"body": "from google apps scritpt",
"click_action": "site",
"icon": "http://url-to-an-icon/icon.png"
},
"to": "key"
};
var response = UrlFetchApp.fetch("https://fcm.googleapis.com/fcm/send", options);
}
需要发生的是,从Google Apps脚本 function firebaseNotification()
开始,但是在此触发并可以发布所需的数据和网络应用以接收推送通知
What needs to happen is that from Google Apps Script function firebaseNotification()
but be triggered there and can POST the data needed and the web app to receive the push notification
推荐答案
此修改如何?
function firebaseNotification() {
var headers = {
"Authorization" : "key=key"
};
// Modified
var payload = {
"notification": {
"title": "CWMS",
"body": "from google apps scritpt",
"click_action": "site",
"icon": "http://url-to-an-icon/icon.png"
},
"to": "key"
};
// Modified
var options = {
method: "POST",
contentType: "application/json",
headers: headers,
payload: JSON.stringify(payload) // <--- Modified
}
var response = UrlFetchApp.fetch("https://fcm.googleapis.com/fcm/send", options);
}
参考:
- 获取(URL,参数)
如果此修改不能解决您的问题,我深表歉意.那时,请再次检查用于授权的参数.
If this modification didn't resolve your issue, I apologize. At that time, please check the parameters for authorizing again.
这篇关于如何发送来自Google Apps脚本的POST数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!