Erorr通过发送电话号码从PFCloud到twilio的parse.com

时间:2016-01-18 21:57:53

标签: ios objective-c node.js parse-platform twilio

我尝试从ios应用程序发送电话号码到Parse.com服务器,通过Twilio,发送短信验证码,我完全像解析指南一样,但我仍然收到错误: " [错误]:哦,出了点问题(代码:141,版本:1.12.0)", 云中的代码是:

var accountSid = 'myAccountSid'; 
    var authToken = "{{ auth_token }}"; 

// Include the Twilio Cloud Module and initialize it
var twilio = require("twilio");
twilio.initialize(accountSid,authToken);

// Create the Cloud Function
Parse.Cloud.define("inviteWithTwilio", function(request, response) {
                   // Use the Twilio Cloud Module to send an SMS
                   twilio.sendSMS({
                                  From: "myTwilioPoneNumber",
                                  To: request.params.number,
                                  Body: "Start using Parse and Twilio!"
                                  }, {
                                  success: function(httpResponse) { response.success("SMS sent!"); },
                                  error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
                                  });
                   });

我的应用中的代码:ViewController.m

- (IBAction)sendMessageButton:(id)sender {
    NSString *toPhoneNumber =@"+1819873435";//etc.
    NSDictionary *params = [NSDictionary dictionaryWithObject:number forKey:@"number"];
    // Call our Cloud Function that sends an SMS with Twilio
    [PFCloud callFunctionInBackground:@"inviteWithTwilio"
                       withParameters:params
                                block:^(id object, NSError *error) {
                                }];
}

我是客户开发人员而我没有任何解决方案。 我该如何解决这个错误?

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

看起来您正在尝试在Parse中使用旧版本的Twilio Cloud模块。您不再需要调用initialize并且sendSMS函数接受一个接收错误和响应参数的回调。代码看起来应该更像这样:

var accountSid = 'myAccountSid'; 
    var authToken = "{{ auth_token }}"; 

// Include the Twilio Cloud Module and initialize it
var twilio = require("twilio")(accountSid, authToken);

// Create the Cloud Function
Parse.Cloud.define("inviteWithTwilio", function(request, response) {
  // Use the Twilio Cloud Module to send an SMS
  twilio.sendSMS({
    From: "myTwilioPoneNumber",
    To: request.params.number,
    Body: "Start using Parse and Twilio!"
  }, function(err, response) {
    if (!err) {
      response.success("SMS sent!");
    } else {
      response.error("Uh oh, something went wrong");
    }
  });
});