Plivo:尝试发送短信时出错

时间:2016-03-14 09:13:33

标签: ruby-on-rails sms plivo

我一直收到此错误:" 757:'意外令牌无法验证该网址的访问权限级别。您必须使用适当的凭据登录" 在我的Ruby on Rails应用程序中。

以下是代码:

  def send_message_plivo
    p = RestAPI.new(ENV["PLIVO_AUTHID"], ENV["PLIVO_AUTHTOKEN"])

    params = {
      "src" => "1111111111",
      "dest" => "xxxxxxxxxxxxx", # <- my only verified number
      "text" => "Hi! From Plivo",
      "url" => "http://localhost:3000/sent_message_status",
      "method" => "POST"
    }

    response = p.send_message(params) # <- line of the error!
    puts response

  end

你知道我错过了什么吗?

2 个答案:

答案 0 :(得分:0)

根据plivo.com/docs/api/message,参数假设为&#34; dst&#34;不是&#34; dest&#34;。

另外,仔细检查您的Plivo Auth ID和Auth Token使用的值。确保您使用的是AUTH ID(20ish&#34; random&#34;字符串),而不是您的Plivo用户名。

答案 1 :(得分:0)

你必须做这样的事情: -

        $auth_id = 'PLIVO_AUTHID';
    $auth_token = 'PLIVO_AUTHTOKEN';

    $p = new RestAPI($auth_id, $auth_token);

    // Set message parameters
    $params = array(
            'src' => '1111111111', // Sender's phone number with country code
            'dst' => '2222222222', // Receiver's phone number with country code
            'text' => 'Hi, Message from Plivo', // Your SMS text message

            //'url' => 'http://example.com/report/', // The URL to which with the status of the message is sent
            'method' => 'GET' // The method used to call the url
    );
    // Send message
    $response = $p->send_message($params);

    // Print the response
    echo "Response : ";
    print_r ($response['response']);

    // Print the Api ID
    echo "<br> Api ID : {$response['response']['api_id']} <br>";

    // Print the Message UUID
    echo "Message UUID : {$response['response']['message_uuid'][0]} <br>";

如果你得到这样的回应: -

Response : Array ( [api_id] => 2c5af359-1c06-11e6-8a00-22000ae28743 [message] => message(s) queued [message_uuid] => Array ( [0] => 0f2afda3-b869-45f6-9baf-13acc1992cb8 ) ) Api ID : 2c5af359-1c06-11e6-8a00-22000ae28743 Message UUID : 0f2afda3-b869-45f6-9baf-13acc1992cb8 

表示您的邮件已发送。