2016-03-14 72 views
0

我一直收到这个错误:“757:意外的令牌在'无法验证您的访问级别的URL。您必须使用正确的凭据登录” 在我的Ruby on Rails应用程序。Plivo:尝试发送短信时出错

下面的代码:

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 

你知道我缺少什么?

+0

是真的假设为“dest”的参数吗?我在这里看到“dst”:https://www.plivo.com/docs/api/message/ –

+0

对于PLIVO_AUTHID,你使用你的plivo用户名还是AUTH ID(20ish“random”字符串)? –

+0

你是对的。我有问题的env变量,我直接把键,并将“dest”改为“dst”,它的工作! – ste

回答

0

根据plivo.com/docs/api/message该参数假设为“dst”而不是“dest”。

此外,仔细检查您用于您的Plivo身份验证ID和身份验证令牌的值。确保你使用你的AUTH ID(20个“随机”字符串),而不是你的Plivo用户名。

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 

这意味着发送您的消息。