gpt4 book ai didi

javascript - Google-app-script 错误左侧分配无效

转载 作者:行者123 更新时间:2023-11-30 15:09:43 25 4
gpt4 key购买 nike

您好,我在 google apps 脚本中找不到这个错误。我检查了我的代码很多时间,但什么也没有。此代码用于与入站营销一起使用的服务中的 webhook,其中我有一些弹出窗体来获取我的时事通讯的用户,我希望我的 Mail chimp 帐户的订阅者只是发送有关博客的更新。所以我正在使用下面的代码来执行此操作,但出现此错误。对不起,如果我的代码错了。JSON源是这样的https://github.com/ResultadosDigitais/rdocs/blob/master/rdstation_integration.json我创建的 md5Hash 函数,用于给出字符串的哈希值。

如果有人能帮助我,非常感谢!

//receive the request
function doPost(e){
return mcResponse(e);
}

//Send information to MC
function mcResponse(n){
var email = n.parameter["leads[email]"];
var nome = n.parameter["leads[name]"];
var hash = md5Hash(email);

try {

var bodyData = [];
var mergeFields = ["FNAME" = nome];
bodyData.push([
"email_address" = email,
"status_if_new" = "subscribed",
"status" = "subscribed",
"merge_fields" = mergeFields
]);

var headers = {
'Content-type': 'application/json',
'Authorization': 'apikey ' + API_KEY_MC
};

var options = {
'method': 'PUT',
'headers': JSON.stringify(headers),
'payload': JSON.stringify(bodyData)
};

var response = UrlFetchApp.fetch(MC_URL + LIST_ID + '/members/' + hash, options);
return ContentService.createTextOutput(response.getContentText());

} catch(e){
return ContentService.createTextOutput(e);
}
}

最佳答案

错误是由这一行引起的:

var mergeFields = ["FNAME" = nome];

将其更改为:

var mergeFields = {"FNAME": nome};

此代码块相同:

bodyData.push([
"email_address" = email,
"status_if_new" = "subscribed",
"status" = "subscribed",
"merge_fields" = mergeFields
]);

改成

bodyData.push({
"email_address": email,
"status_if_new": "subscribed",
"status": "subscribed",
"merge_fields": mergeFields
});

有关 JavaScript 中对象文字的详细信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Object_literals

关于javascript - Google-app-script 错误左侧分配无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45281341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com