【问题标题】:Sending an SMS through Twilio letting it chose the From number with a MessagingServiceSid doesn't work通过 Twilio 发送 SMS 让它选择带有 MessagingServiceSid 的 From 号码不起作用
【发布时间】:2016-08-02 06:50:07
【问题描述】:

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

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

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

$ 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
}

【问题讨论】:

  • 您是否为您的消息服务设置了电话号码?

标签: twilio


【解决方案1】:

我可以看到您在 MessageService 中有一个数字,但您似乎使用的是不支持 sending with the MessageService 的旧的已弃用端点。

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

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

试一试,告诉我进展如何。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多