首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Plivo:尝试发送SMS时出错

Plivo:尝试发送SMS时出错
EN

Stack Overflow用户
提问于 2016-03-14 17:13:33
回答 2查看 1.8K关注 0票数 0

在我的Ruby on Rails应用程序中,我一直收到这样的错误:"757:意外的令牌‘无法验证您对该URL的访问级别。您必须使用正确的凭据登录“。

代码如下:

代码语言:javascript
复制
  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

你知道我错过了什么吗?

EN

回答 2

Stack Overflow用户

发布于 2016-03-16 02:04:15

根据plivo.com/docs/api/message,参数应该是"dst“而不是"dest”。

此外,请仔细检查您的Plivo Auth ID和Auth Token所使用的值。确保您使用的是您的身份验证ID (20左右的“随机”字符串),而不是您的Plivo用户名。

票数 0
EN

Stack Overflow用户

发布于 2016-05-17 16:24:30

你必须这样做:

代码语言:javascript
复制
        $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>";

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

代码语言:javascript
复制
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 

这意味着您的消息已发送。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35983453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档