【问题标题】:Can't get status of sms from Twilio无法从 Twilio 获取短信状态
【发布时间】:2014-10-02 01:04:31
【问题描述】:

我在使用 Twilio API 时遇到了一些问题。我尝试获取已发送、排队、失败或其他状态的短信状态,但在 Rest API 中找不到此方法。

我使用 Python 和 Django。

def send_sms(self, msg):
    ACCOUNT_SID = self.profile.twilio_sid
    AUTH_TOKEN = self.profile.twilio_auth_token
    client_phone_number = self.profile.phone_number
    twilio_phone_number = "+1"+str(self.profile.twilio_number)
    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
    message = client.messages.create(
        body=msg,
        to=client_phone_number,
        from_=twilio_phone_number,
    )
    sid = message.sid

那么我怎样才能通过我所拥有的 sid 获得短信状态?如果可能,不进行响应处理

我找到了答案。我需要的所有内容都添加到我的代码中

body  = client.messages.get(sid)
status =body.status  

【问题讨论】:

    标签: python sms response twilio status


    【解决方案1】:

    Twilio 布道者在这里。

    要获取单个实例资源,请使用 resources.ListResource.get()。提供您想要获取的资源的 sid。

    msg  = client.messages.get(sid)
    print msg.to
    

    您还可以在发送消息时提供状态回调 URL,以便 Twilio 在消息状态更改时通过 webhook 请求通知您:

    https://www.twilio.com/docs/api/rest/sending-messages#post-parameters-optional

    希望对您有所帮助。

    【讨论】:

    • 谢谢,你真的帮我从回复中获取上下文。
    【解决方案2】:

    我找到了答案。我需要的所有内容都添加到我的代码中

    body  = client.messages.get(sid)
    status = body.status  
    

    【讨论】:

      【解决方案3】:
      Message message = twilio.GetMessage(messageSid);
      

      【讨论】:

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