我使用 twilio 作为移动验证机制,我之前没有使用 twilio 的经验,但是查看示例 PHP 代码我在我的代码中使用了这个代码,但显然它给了我一个 400 Bad request HTTP 错误。这是代码:

    d = {
        'TO' : '*** *** ****',
        'FROM' : '415-555-1212',
        'BODY' : 'Hello user, please verify your device using                    this code %s' % verNumber
    }
    try:
        print account.request('/%s/Accounts/%s/SMS/Messages' % \
                            (API_VERSION, ACCOUNT_SID), 'POST', d)
    except Exception, e:
        return HttpResponse('Error %s' % e)
verNumber 是随机生成的,接收者的号码在 twilio 中进行验证。

我按照异常发现了这个错误
Error 400 The source 'From' phone number is required to send an SMS

这是什么意思。?

谢谢。

最佳答案

查看 python 库中的 some of the twilio examples,我注意到包含有效负载的字典是以 MixedCase 键入的,而您使用的是大写。

错误可能很直接,而不是

d = {
    'TO' : '*** *** ****',
    'FROM' : '415-555-1212',
    'BODY' : 'Hello user, please verify your device using this code %s' % verNumber
}

尝试
d = {
    'To' : '*** *** ****',
    'From' : '415-555-1212',
    'Body' : 'Hello user, please verify your device using this code %s' % verNumber
}

SMS Quickstart(在文档中)支持这个想法。

希望这可以帮助。

关于姜戈 | twilio 发送短信,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2863201/

10-12 13:00
查看更多