问题描述
我有这个代码块遍历 Twilio 消息列表..但我一直为 DateSent(或 DateCreated)获取 null,我我正在寻找 bakc 消息的时间戳.其他一切(其他字段,从,到,正文都可以正常工作)
I have this code block iterating through the Twilio Message list.. but I keep getting null for DateSent (or DateCreated), I'm looking to get bakc the timestamp of the message. Everything else (the other fields , from, to , body all work fine)
$client = new Services_Twilio($twilio['sid'],$twilio['token']);
// Loop over the list of messages echo each key property
foreach ($client->account->messages as $message) {
$list_sms_messages[]=array('timestamp'=>$message->dateSent,
'from'=>$message->from ,
'to'=>$message->to,
'body'=> $message->body );
}
根据 API DateSent 或 (DateCreated) 应该在消息列表对象中.任何想法
According to the API DateSent or (DateCreated) should be in the message list object. Any ideas
推荐答案
我自己也遇到过这个问题.看到您正在使用 PHP 库,我可以尝试为您解决此问题.在本节中:
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 property
foreach ($client->account->messages as $message) {
$list_sms_messages[]=array(
'timestamp'=>$message->dateSent,
'from'=>$message->from ,
'to'=>$message->to,
'body'=> $message->body
);
}
$message->dateSent
实际上是一个 PHP DateObject,因此您可以通过将其更改为:$message->dateSent->getTimestamp()
The $message->dateSent
is actually a PHP DateObject so you can fetch the timestamp in Epoch format by change it to: $message->dateSent->getTimestamp()
然后可以使用 date()
函数格式化返回的时间戳.
The returned timestamp can then be formatted with the date()
function.
我希望这会有所帮助.
这篇关于Twilio PHP API 如何获取消息时间戳 DateSent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!