dougui4325 2015-03-19 19:49
浏览 29

Twilio PHP API如何获取消息时间戳DateSent?

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 );
}

According to the API DateSent or (DateCreated) should be in the message list object. Any ideas

  • 写回答

2条回答 默认 最新

  • doujizhong8352 2015-03-19 20:55
    关注

    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,
        }]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看