使用&ttcCallout'与Sinch API进行通话后方法,我试图获得该通话的状态。电话通过,我收到了它的电话号码'。但是,当涉及到请求我的呼叫状态时,我收到200 OK作为HTTP响应并且空(' null')内容。
首先,我虽然我的代码和我形成授权标题的方式有问题(我使用Python,它的请求库和基本身份验证),但后来我尝试了Sinch API资源管理器(https://www.sinch.com/dashboard/#/api)并显示给我的输出相同(参见附页截图)。必须注意这个代码大约一个月前工作,我能够获得通话状态。
此外,这是我用来与Sinch API进行通信的代码。
class CallNotification(Notification):
def __init__(self, data):
self.id = ""
self.call = self.data['call']
self.api_url = self.call['api_url']
self.auth = ("application:" + self.call['auth']['key'], self.call['auth']['secret'])
self.status = {'http': "new", 'result': "none", 'reason': "none"}
def send(self):
request_url = self.api_url + "/callouts"
request = requests.post(request_url,
auth=self.auth,
json={
'method': "ttsCallout",
'ttsCallout': {
'cli': "private",
'destination': {
'type': "number",
'endpoint': self.call['to']
},
'domain': "pstn",
'custom': "customData",
'locale': "en-US",
'text': self.call['message']
}
},
headers={'content-type': 'application/json'})
self.id = json.loads(request.content)['callId']
self.status['http'] = request.reason
return self.status['http']
def getstatus(self):
if not self.status['http'] == "new":
request_url = self.api_url + "/calls/id/" + self.id
request = requests.get(request_url,
auth=self.auth,
headers={'Content-type': 'application/json'})
try:
self.status['result'] = json.loads(request.content)['result']
except TypeError:
self.status['result'] = "Sent/Unknown"
return self.status['result']
我做错了吗?如何获取已拨打电话的状态?