解析集成第三方服务

时间:2014-12-02 23:34:09

标签: parse-platform cloud-code

我目前正在关注教程https://parse.com/tutorials/integrating-with-third-party-services

在模块中,sendEmail函数设置如下:

sendEmail: function(params, options) {
  return Parse.Cloud.httpRequest({
    method: "POST",
    url: "https://api:" + key + "@" + url + "/" + domain + "/messages",
    body: params,
  }).then(function(httpResponse) {
    if (options && options.success) {
      options.success(httpResponse);
    }
  }, function(httpResponse) {
    if (options && options.error) {
      options.error(httpResponse);
    }
  });
}

每当我使用curl运行该函数并尝试使用console.log选项哈希时,选项哈希始终是未定义的。

结果是我无法在回调中获得httpResponse对象

Parse.Cloud.define("sendEmailToUser", function(request, response) {
  client.sendEmail({
    to: "email@example.com",
    from: "MyMail@CloudCode.com",
    subject: "Hello from Parse!",
    text: "Using Parse and My Mail Module is great!"
  }).then(function(httpResponse) {
    response.success("Email sent!");
  }, function(httpResponse) {
    console.error(httpResponse);
    response.error("Uh oh, something went wrong");
  });
});

如何在上面的回调中获取httpResponse对象?

1 个答案:

答案 0 :(得分:0)

你只需要返回你得到的结果,然后它会继续传递给下一个成功/错误处理程序

sendEmail: function(params, options) {
  return Parse.Cloud.httpRequest({
    ...
  }).then(function(httpResponse) {
    if (options && options.success) {
      options.success(httpResponse);
    }
    return httpResponse
  }, function(httpResponse) {
    if (options && options.error) {
      options.error(httpResponse);
    }
    return httpResponse
  });
}