Uncaught Error: Can't form encode an Object
Uncaught Error: Can't form encode an Object
我正在尝试调用我为 Mailgun 编写的一些 Parse CloudCode,但是当我从我的 iOS 应用程序调用它时,我得到的是:
E2015-09-16T05:52:37.410Z]v4 after_save triggered for EmailConfirmations for user HjHSYVX56t:
Input: {"object":{"createdAt":"2015-09-
16T05:52:37.399Z","email1":"test@trever.me","email2":"test@trever.me","name1":"Test Test","name2":"Test Test","objectId":"KPLpKdZqSO","updatedAt":"2015-09-16T05:52:37.399Z"}}
Result: Uncaught Error: Can't form encode an Object
我从 Parse 控制台得到这个,有谁知道这到底是什么意思?
谢谢!
这是我的 CloudCode:
// bring in Mailgun
var Mailgun = require('mailgun');
// init Mailgun
Mailgun.initialize('sandboxcf52f1abbe6f4bbe80c055aecc31f58f.mailgun.org', 'key-b29acfb8411921998764456e247c30fa');
Parse.Cloud.afterSave("EmailConfirmations", function(request) {
// This function runs on INSERT and DELETE operations.
// Check to ensure account is new.
if (!request.object.existed()) {
var email1 = request.object.get("email1");
var email2 = request.object.get("email2");
var name1 = request.object.get("name1");
var name2 = request.object.get("name2");
var tradeDateTime = request.object.get("tradeDateTime");
var body = "Hello " + name1 + "&" + name2 + ",\n\n Your trade on" + tradeDateTime +
"has been approved, and will need to be processed in Empower, or via an Expresso ticket. " +
"Please process as soon as possible to ensure a successful trade.";
var sender = "test@test.com";
var subject = "Trade Confirmation";
}
Mailgun.sendEmail(
{
to: [email1, email2],
from: sender,
subject: subject,
text: body
}, onMailComplete, onMailError);
function onMailComplete (httpResponse) {
console.log(httpResponse);
console.log("Email sent to " + email1 + "and" + email2);
}
function onMailError (httpResponse) {
console.error(httpResponse);
console.error("Uh oh, something went wrong");
}
} /* eo func def */
);
这是我调用云函数的代码:
PFCloud.callFunctionInBackground("EmailConfirmations", withParameters: ["objectId": objectID, "email1" : emailCurrentUser, "email2" : emailCurrentUser, "name1" : fullnameCurrentUser, "name2" : fullnameCurrentUser])
我猜你试图发送一个 HTTP 请求,将对象作为参数传递给它期望的字符串。在传递之前使用JSON.stringify(object)
。
有关详细信息,请参阅:https://parse.com/questions/result-uncaught-error-cant-form-encode-an-object
编辑:
现在我完全..不明白发生了什么。您应该重新阅读 Parse Cloud 指南,因为您将 afterSave 挂钩与云函数调用混合在一起,它们是不同的东西。
我猜你的云代码应该是这样的:
// bring in Mailgun
var Mailgun = require('mailgun');
// init Mailgun
Mailgun.initialize('sandboxcf52f1abbe6f4bbe80c055aecc31f58f.mailgun.org', 'key-b29acfb8411921998764456e247c30fa');
Parse.Cloud.define("EmailConfirmations", function(request) {
var email1 = request.params.email1;
var email2 = request.params.email2;
var name1 = request.params.name1;
var name2 = request.params.name2;
var tradeDateTime = request.params.tradeDateTime;
var body = "Hello " + name1 + "&" + name2 + ",\n\n Your trade on" + tradeDateTime +
"has been approved, and will need to be processed in Empower, or via an Expresso ticket. " +
"Please process as soon as possible to ensure a successful trade.";
var sender = "test@test.com";
var subject = "Trade Confirmation";
Mailgun.sendEmail({
to: [email1, email2],
from: sender,
subject: subject,
text: body
}, onMailComplete, onMailError);
function onMailComplete (httpResponse) {
console.log(httpResponse);
console.log("Email sent to " + email1 + "and" + email2);
}
function onMailError (httpResponse) {
console.error(httpResponse);
console.error("Uh oh, something went wrong");
}
} /* eo func def */
);
并且在 swift 函数调用中您可以跳过 objectID
但您应该添加类型为 NSDate
的 tradeDateTime
我正在尝试调用我为 Mailgun 编写的一些 Parse CloudCode,但是当我从我的 iOS 应用程序调用它时,我得到的是:
E2015-09-16T05:52:37.410Z]v4 after_save triggered for EmailConfirmations for user HjHSYVX56t:
Input: {"object":{"createdAt":"2015-09-
16T05:52:37.399Z","email1":"test@trever.me","email2":"test@trever.me","name1":"Test Test","name2":"Test Test","objectId":"KPLpKdZqSO","updatedAt":"2015-09-16T05:52:37.399Z"}}
Result: Uncaught Error: Can't form encode an Object
我从 Parse 控制台得到这个,有谁知道这到底是什么意思?
谢谢!
这是我的 CloudCode:
// bring in Mailgun
var Mailgun = require('mailgun');
// init Mailgun
Mailgun.initialize('sandboxcf52f1abbe6f4bbe80c055aecc31f58f.mailgun.org', 'key-b29acfb8411921998764456e247c30fa');
Parse.Cloud.afterSave("EmailConfirmations", function(request) {
// This function runs on INSERT and DELETE operations.
// Check to ensure account is new.
if (!request.object.existed()) {
var email1 = request.object.get("email1");
var email2 = request.object.get("email2");
var name1 = request.object.get("name1");
var name2 = request.object.get("name2");
var tradeDateTime = request.object.get("tradeDateTime");
var body = "Hello " + name1 + "&" + name2 + ",\n\n Your trade on" + tradeDateTime +
"has been approved, and will need to be processed in Empower, or via an Expresso ticket. " +
"Please process as soon as possible to ensure a successful trade.";
var sender = "test@test.com";
var subject = "Trade Confirmation";
}
Mailgun.sendEmail(
{
to: [email1, email2],
from: sender,
subject: subject,
text: body
}, onMailComplete, onMailError);
function onMailComplete (httpResponse) {
console.log(httpResponse);
console.log("Email sent to " + email1 + "and" + email2);
}
function onMailError (httpResponse) {
console.error(httpResponse);
console.error("Uh oh, something went wrong");
}
} /* eo func def */
);
这是我调用云函数的代码:
PFCloud.callFunctionInBackground("EmailConfirmations", withParameters: ["objectId": objectID, "email1" : emailCurrentUser, "email2" : emailCurrentUser, "name1" : fullnameCurrentUser, "name2" : fullnameCurrentUser])
我猜你试图发送一个 HTTP 请求,将对象作为参数传递给它期望的字符串。在传递之前使用JSON.stringify(object)
。
有关详细信息,请参阅:https://parse.com/questions/result-uncaught-error-cant-form-encode-an-object
编辑:
现在我完全..不明白发生了什么。您应该重新阅读 Parse Cloud 指南,因为您将 afterSave 挂钩与云函数调用混合在一起,它们是不同的东西。
我猜你的云代码应该是这样的:
// bring in Mailgun
var Mailgun = require('mailgun');
// init Mailgun
Mailgun.initialize('sandboxcf52f1abbe6f4bbe80c055aecc31f58f.mailgun.org', 'key-b29acfb8411921998764456e247c30fa');
Parse.Cloud.define("EmailConfirmations", function(request) {
var email1 = request.params.email1;
var email2 = request.params.email2;
var name1 = request.params.name1;
var name2 = request.params.name2;
var tradeDateTime = request.params.tradeDateTime;
var body = "Hello " + name1 + "&" + name2 + ",\n\n Your trade on" + tradeDateTime +
"has been approved, and will need to be processed in Empower, or via an Expresso ticket. " +
"Please process as soon as possible to ensure a successful trade.";
var sender = "test@test.com";
var subject = "Trade Confirmation";
Mailgun.sendEmail({
to: [email1, email2],
from: sender,
subject: subject,
text: body
}, onMailComplete, onMailError);
function onMailComplete (httpResponse) {
console.log(httpResponse);
console.log("Email sent to " + email1 + "and" + email2);
}
function onMailError (httpResponse) {
console.error(httpResponse);
console.error("Uh oh, something went wrong");
}
} /* eo func def */
);
并且在 swift 函数调用中您可以跳过 objectID
但您应该添加类型为 NSDate
tradeDateTime