Created
July 24, 2018 00:11
-
-
Save kiuchikeisuke/486abf22cb1d225c74738562005a5444 to your computer and use it in GitHub Desktop.
FCMの対象端末へのプッシュ通知をGAS使って簡単に実現する ref: https://qiita.com/k_keisuke/items/f670d2a3d7f78126f2f5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Const = { | |
FCMServerKey: "AAAAW1C_znk:APA91bHcG..." | |
} | |
function sendNotification(token, value1, value2) { | |
var data = { | |
"to": token, | |
"data":{ | |
"value1": value1, //hogehoge | |
"value2": value2 //mogemoge | |
} | |
} | |
var auth = "key=" + Const.FCMServerKey; | |
var headers = { | |
'Authorization': auth, | |
"contentType" : "application/json", | |
}; | |
var options = { | |
"method" : "post", | |
"payload" : data, | |
"headers" : headers, | |
"muteHttpExceptions": true | |
}; | |
var url = "https://fcm.googleapis.com/fcm/send"; | |
var res = UrlFetchApp.fetch(url, options); | |
Logger.log(res); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment