我需要传递一个变量,而不是json.stringify中的令牌值
我可以在google-apps脚本中使用以下代码将令牌发送到FCM:
function sendtokens() {
//lets say my variable is:
var token = ...
var response = UrlFetchApp.fetch('https://iid.googleapis.com/iid/v1:batchAdd', {
method: 'POST',
contentType: 'application/json',
headers: {
Authorization: 'key=AAAAB.....LK',
},
payload: JSON.stringify({
to: '/topics/test' ,
// the following works well:
registration_tokens: ['dNxYMH....K7O'],
// i want to know how to write:
registration_tokens: [' + token +'],
})
});
Logger.log(response);
}
我想放置标记的变量而不是标记本身,我试图在引号“”和''之间写变量,但它们都不起作用
答案 0 :(得分:0)
如本指南中所述: https://developers.google.com/apps-script/guides/services/external 使用stringify解决问题的方法如下:
var data = {
'entry': {
'group': {
'title': 'Dog Skateboarding',
'description': 'My dog gets some serious air'
},
'keywords': 'dog, skateboard'
}
}
var payload = JSON.stringify(data);
谢谢大师和专家。