使用twilio将视频网址添加到短信或短信

时间:2017-12-04 16:52:36

标签: ruby-on-rails ruby youtube twilio

我可以在下面的新消息“body”添加YouTube链接,它会发送消息,但添加media_url的链接会出现mime类型错误。请问我对这种方法的看法。

client = Twilio::REST::Client.new 'Axx', 'xx'
message = client.messages.create 
    from: '+1xxxxxxxxxx', 
    to: 'xxxxxxxxxx', 
    body: "Learning to send SMS you are. \n https://www.youtube.com/watch?v=aBlKPLeLU_s"

是否有更好的方法可以将YouTube链接添加到新邮件中?

修改

将网址添加到media_url键,如

client = Twilio::REST::Client.new 'Axx', 'xx'
message = client.messages.create 
    from: '+1xxxxxxxxxx', 
    to: 'xxxxxxxxxx', 
    body: "Learning to send SMS you are." 
    media_url: "https://www.youtube.com/watch?v=aBlKPLeLU_s"

给出twilio的错误

  

信息=尝试+至+检索+ MediaUrl +返回+的+不受支持+的Content-Type&安培; EmailNotification =假安培;的contentType =文本%2Fhtml&安培; LogLevel的= ERROR&安培; URL = HTTPS%3A%2F%2Fwww.youtube .COM%2Fembed%2FaBlKPLeLU_s

2 个答案:

答案 0 :(得分:2)

Twilio开发者传道者在这里。

使用Twilio通过彩信发送媒体时,需要链接到媒体文件本身。在您的示例中,您只是链接到YouTube页面,而不是视频文件。

其他一些注意事项。 The list of MIME types that Twilio will accept is listed here。另外,Twilio will not send media messages that are over 5MB total size

希望这有帮助。

答案 1 :(得分:1)

  

Twilio的media_url示例

Twilio

  var mediaUrl = new List<Uri>() {
      new Uri("http://www.example.com/hearts.png")
  };
  var to = new PhoneNumber("+14158141829");
  var message = MessageResource.Create(to,
                  from: new PhoneNumber("+15558675309"),
                  body: "Jenny please?! I love you <3",
                  mediaUrl: mediaUrl);
  

还有允许的选项链接

Twilio Create function arguments

  

你能试试......

client = Twilio::REST::Client.new 'Axx', 'xx'
  message = client.messages.create 
  from: '+1xxxxxxxxxx', 
  to: 'xxxxxxxxxx', 
  body: "Learning to send SMS you are." 
  media_url: [URI("https://www.youtube.com/watch?v=aBlKPLeLU_s")]