通过 Twilio 发送短信让它选择带有 MessagingServiceSid 的发件人号码不起作用 [英] Sending an SMS through Twilio letting it chose the From number with a MessagingServiceSid doesn't work

查看:43
本文介绍了通过 Twilio 发送短信让它选择带有 MessagingServiceSid 的发件人号码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 twilio 发送短信,但没有指定特定的发件人号码,而是让 Copilot 为我选择最佳号码(如 https://www.twilio.com/docs/api/rest/sending-messages#post-parameters-conditional).

I'm trying to send an SMS using twilio, without specifying a specific From number, instead letting Copilot chose the best number for me (as documented in https://www.twilio.com/docs/api/rest/sending-messages#post-parameters-conditional).

但是,在发送请求时,Twilio REST API 会抱怨我没有指定发件人编号.正如预期的那样,指定发件人编号有效.但是我想避免这种情况,以便在将来需要更多数字时更加灵活.我误解了文档吗?

However, when sending a request, the Twilio REST API complains that I did not specify a From number. Specifying a From number, as expected, works. But I'd like to avoid this to be more flexible in case I need more numbers down the road. Am I misunderstanding the documentation ?

我使用 HTTPie 来测试 API.完整的请求/响应:

I used HTTPie to test the API. The full request/response :

$ http --print=HBhb --form POST 'https://$ACCOUNT_SID:$ACCOUNT_TOKEN@api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/SMS/Messages.json' MessagingServiceSid=$SERVICE_SID To=$PHONE Body=Hello

POST /2010-04-01/Accounts/$ACCOUNT_SID/SMS/Messages.json HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: Basic REDACTED
Connection: keep-alive
Content-Length: 83
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: api.twilio.com
User-Agent: HTTPie/0.9.2

MessagingServiceSid=$SERVICE_SID&To=$PHONE&Body=Hello

HTTP/1.1 400 BAD REQUEST
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since
Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Connection: keep-alive
Content-Length: 136
Content-Type: application/json
Date: Thu, 28 Jul 2016 14:54:38 GMT
Twilio-Request-Duration: 0.056
Twilio-Request-Id: RQ5b9acf9d222947668fa9ada38d5beaba
X-Powered-By: AT-5000
X-Shenanigans: none

{
    "code": 21603, 
    "message": "A 'From' phone number is required.", 
    "more_info": "https://www.twilio.com/docs/errors/21603", 
    "status": 400
}

推荐答案

我可以看到您在 MessageService 中有一个数字,但是看起来您正在使用不支持 使用 MessageService 发送.

I can see that you have a number in the MessageService, however it looks like you are using the old deprecated endpoint that does not support sending with the MessageService.

您有:/2010-04-01/Accounts/$ACCOUNT_SID/SMS/Messages.json

您应该使用:/2010-04-01/Accounts/$ACCOUNT_SID/Messages.json

试试看,让我知道它是怎么回事.

Give that a try and let me know how it goes.

这篇关于通过 Twilio 发送短信让它选择带有 MessagingServiceSid 的发件人号码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆