Twilio Php Api How To Get Message Timestamp Datesent?
Solution 1:
I've come across this issue myself. Seeing as you're using the PHP library I can try resolve this issue for you. In this section:
// Loop over the list of messages echo each key propertyforeach ($client->account->messages as$message) {
$list_sms_messages[]=array(
'timestamp'=>$message->dateSent,
'from'=>$message->from ,
'to'=>$message->to,
'body'=> $message->body
);
}
The $message->dateSent
is actually a PHP DateObject so you can fetch the timestamp in Epoch format by change it to: $message->dateSent->getTimestamp()
The returned timestamp can then be formatted with the date()
function.
I hope this helps.
Solution 2:
I figured it out by poking around TWILIO site examples, it turns out that their API guide for their TWIL formatted JSON ( and XML) uses different property names than their TWILIO-PHP wrapper library.. Here's the typical Message JSON when using the PHP library ( i omitted some fields for privacy reasons), but as you can see:
- DateSent is actually date_sent ,
- DateCreated is actually date_created and so on..
Once I plugged that into my code it worked as expected...
"messages":[{"sid":"SM37e1d0d26f2ac513fbb30024a10e98fc","date_created":"Thu, 19 Mar 2015 20:14:22 +0000","date_updated":"Thu, 19 Mar 2015 20:14:22 +0000","date_sent":"Thu, 19 Mar 2015 20:14:22 +0000","account_sid":"AC2a0f5850342e7c43785ab72742e0bec0","to":"+17324918525","from":"+19733438312","body":"Si","status":"received","num_segments":"1","num_media":"0","direction":"inbound","api_version":"2010-04-01","price":"-0.00750","price_unit":"USD","error_code":null,"error_message":null,}]
Post a Comment for "Twilio Php Api How To Get Message Timestamp Datesent?"