我们使用和。当我提出请求时,如何获得该请求的状态。它是否返回了一个好的2XX,一个错误4XX?我不是说,这些信息的状态是什么。我的意思是,twilio收到我的API调用了吗?
在Postman中使用REST进行测试时,如果一切顺利,我通常会得到200或201响应。
$twilio = new Client($acct_sid, $token);
$Addresses = array("+12015551234");
$toBindingAttributes = array();
foreach ($Addresses as $Address) {
array_push($toBindingAttributes, '{"binding_type":"sms","address":"' . $Address . '"}');
}
$notification = $twilio->notify->services($notify_sid)
->notifications->create([
"toBinding" => $toBindingAttributes,
"body" => "Twilio Test."
]);我试着把$notification还给我,我只得到了[Twilio.Notify.V1.NotificationInstance]
-----Edit
好的,我现在意识到[Twilio.Notify.V1.NotificationInstance]是一个对象。我能够print_r($notification)并看到有一个statusCode属性。
我试着重复这个属性print_r(@notification->statusCode),但是我得到了“未知属性”。
是因为它是“保护”的吗?[statusCode:protected] => 201
谢谢
发布于 2019-10-25 01:47:31
因为结果是[Twilio.Notify.V1.NotificationInstance]对象。问题是对象中的所有属性都是受保护的,我们不能直接访问它们。
我们能够用一堆strpos,substr和regex找到它们,但是找到了一个更简单的使用getter的方法。
通过这样做,print($twilio->getHttpClient()->lastResponse->getStatusCode());
Twilio-PHP库中的更多信息
https://stackoverflow.com/questions/58495454
复制相似问题