我无法获取教程中所示的 JSON 响应。我已经实现了一个可编程语音程序。我想向用户显示呼叫的详细信息,如果我得到 JSON 响应,我将能够获得所有这些信息(成本、持续时间、状态等)。# views.pydef start_campaign(request, campaign_id): try: campaign = Campaign.objects.get(pk=campaign_id) account_sid = 'XXX' auth_token = 'XXX' client = Client(account_sid, auth_token) phone_numbers = Contact.objects.filter(phone_book=campaign.phone_book) custom_url = 'http://XXX.ngrok.io/assets/' + str(campaign_id) for phone_number in phone_numbers: call = client.calls.create( method='GET', status_callback='http://XXX.ngrok.io/events', status_callback_event='completed', status_callback_method='GET', url=str(custom_url), to=str(phone_number), from_='+1XXX' ) detail = client.calls(str(call.sid)).fetch() print(detail.price) except Campaign.DoesNotExist: raise Http404("Campaign Does Not Exist") context = { 'all_campaigns': campaign } return render(request, "CallCenter/start_campaign.html", context)def events(request): status = request.GET.getlist('CallStatus', default=None) duration = request.GET.getlist('CallDuration', default=None) print("Duration:{}\nStatus:{}".format(duration, status)) return render(request, "CallCenter/events.html")在终端中,我得到一个输出,它打印出呼叫的状态和持续时间打印出来持续时间:['5', '5']状态:['完成','完成']不幸的是,我不知道如何请求 Twilio 的 JSON 响应。我无法获取教程中所示的 JSON 响应。我已经实现了一个可编程语音程序。我想向用户显示呼叫的详细信息,如果我得到 JSON 响应,我将能够获得所有这些信息(成本、持续时间、状态等)。
1 回答
森栏
TA贡献1810条经验 获得超5个赞
收到回调后,您将在 GET 数据中获得 CallSid ID。因此,您可以使用它来获取完整的 Call 资源:
def events(request): sid = request.GET['CallSid'] call = client.calls(sid).fetch() print(call.price)
添加回答
举报
0/150
提交
取消