我在Twilio中创建了一个号码,我正在使用以下代码
foreach ($client->account->messages->get("$sid") as $message) {
echo "<tr><td>" . $message->from . "</td><td>" . $message->date_sent . "</td><td>" . $message->body . "</td></tr>";
}
$sid
是来电号码的SID。
该号码尚未收到任何消息,但HTML输出为
<tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr>
为什么会这样?
按要求编辑:var_dump($message)
输出:
object(Services_Twilio)#1 (8) { ["versions":protected]=> array(2) { [0]=> string(10) "2008-08-01" [1]=> string(10) "2010-04-01" } ["http":protected]=> object(Services_Twilio_HttpStream)#2 (4) { ["auth_header":"Services_Twilio_HttpStream":private]=> string(113) "Authorization: Basic QUMwNDliNjVjMzJiZDBjYWQ2YTIyOWI0NDcxOWFjNjExNjo0OGJlZmEyM2JjZGM2MmFkNDIxNGI0MGU2ZDA1NmIyZQ==" ["uri":"Services_Twilio_HttpStream":private]=> string(22) "https://api.twilio.com" ["debug":"Services_Twilio_HttpStream":private]=> bool(false) ["options":"Services_Twilio_HttpStream":private]=> array(2) { ["http"]=> array(2) { ["user_agent"]=> string(39) "twilio-php/4.10.0 (php 5.6.14-0+deb8u1)" ["header"]=> string(23) "Accept-Charset: utf-8 " } ["ssl"]=> array(2) { ["verify_peer"]=> bool(true) ["verify_depth"]=> int(5) } } } ["last_response":protected]=> object(stdClass)#46 (9) { ["first_page_uri"]=> string(127) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers.json?PhoneNumber=%2B16466635449&Page=0&PageSize=50" ["end"]=> int(0) ["previous_page_uri"]=> NULL ["incoming_phone_numbers"]=> array(1) { [0]=> object(Services_Twilio_Rest_IncomingPhoneNumber)#49 (27) { ["subresources":protected]=> array(0) { } ["client"]=> *RECURSION* ["sid"]=> string(34) "PN4dd1d27307e1ae889c716f38d54759aa" ["account_sid"]=> string(34) "AC049b65c32bd0cad6a229b44719ac6116" ["friendly_name"]=> string(14) "(646) 663-5449" ["phone_number"]=> string(12) "+16466635449" ["voice_url"]=> string(38) "https://demo.twilio.com/welcome/voice/" ["voice_method"]=> string(4) "POST" ["voice_fallback_url"]=> NULL ["voice_fallback_method"]=> string(4) "POST" ["voice_caller_id_lookup"]=> bool(false) ["date_created"]=> string(31) "Wed, 09 Mar 2016 14:25:05 +0000" ["date_updated"]=> string(31) "Wed, 09 Mar 2016 14:25:06 +0000" ["sms_url"]=> string(42) "https://demo.twilio.com/welcome/sms/reply/" ["sms_method"]=> string(4) "POST" ["sms_fallback_url"]=> string(0) "" ["sms_fallback_method"]=> string(4) "POST" ["address_requirements"]=> string(4) "none" ["beta"]=> NULL ["capabilities"]=> object(stdClass)#48 (3) { ["voice"]=> bool(true) ["sms"]=> bool(true) ["mms"]=> bool(true) } ["status_callback"]=> string(0) "" ["status_callback_method"]=> string(4) "POST" ["api_version"]=> string(10) "2010-04-01" ["voice_application_sid"]=> NULL ["sms_application_sid"]=> string(0) "" ["trunk_sid"]=> NULL ["uri"]=> string(111) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers/PN4dd1d27307e1ae889c716f38d54759aa" } } ["uri"]=> string(127) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers.json?PhoneNumber=%2B16466635449&Page=0&PageSize=50" ["page_size"]=> int(50) ["start"]=> int(0) ["next_page_uri"]=> NULL ["page"]=> int(0) } ["retryAttempts":protected]=> int(1) ["version":protected]=> string(10) "2010-04-01" ["subresources":protected]=> NULL ["accounts"]=> object(Services_Twilio_Rest_Accounts)#3 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(28) "Services_Twilio_Rest_Account" ["client"]=> *RECURSION* ["uri"]=> string(20) "/2010-04-01/Accounts" } ["account"]=> object(Services_Twilio_Rest_Account)#4 (5) { ["subresources":protected]=> array(23) { ["applications"]=> object(Services_Twilio_Rest_Applications)#5 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_Application" ["client"]=> *RECURSION* ["uri"]=> string(68) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Applications" } ["available_phone_numbers"]=> object(Services_Twilio_Rest_AvailablePhoneNumbers)#6 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(41) "Services_Twilio_Rest_AvailablePhoneNumber" ["client"]=> *RECURSION* ["uri"]=> string(77) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/AvailablePhoneNumbers" } ["outgoing_caller_ids"]=> object(Services_Twilio_Rest_OutgoingCallerIds)#7 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(37) "Services_Twilio_Rest_OutgoingCallerId" ["client"]=> *RECURSION* ["uri"]=> string(73) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/OutgoingCallerIds" } ["calls"]=> object(Services_Twilio_Rest_Calls)#8 (4) { ["subresources":protected]=> array(1) { ["feedback_summary"]=> object(Services_Twilio_Rest_FeedbackSummary)#9 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(36) "Services_Twilio_Rest_FeedbackSummary" ["client"]=> *RECURSION* ["uri"]=> string(77) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Calls/FeedbackSummary" } } ["instance_name"]=> string(25) "Services_Twilio_Rest_Call" ["client"]=> *RECURSION* ["uri"]=> string(61) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Calls" } ["conferences"]=> object(Services_Twilio_Rest_Conferences)#10 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(31) "Services_Twilio_Rest_Conference" ["client"]=> *RECURSION* ["uri"]=> string(67) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Conferences" } ["incoming_phone_numbers"]=> object(Services_Twilio_Rest_IncomingPhoneNumbers)#11 (4) { ["subresources":protected]=> array(3) { ["local"]=> object(Services_Twilio_Rest_Local)#12 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(40) "Services_Twilio_Rest_IncomingPhoneNumber" ["client"]=> *RECURSION* ["uri"]=> string(82) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers/Local" } ["toll_free"]=> object(Services_Twilio_Rest_TollFree)#13 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(40) "Services_Twilio_Rest_IncomingPhoneNumber" ["client"]=> *RECURSION* ["uri"]=> string(85) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers/TollFree" } ["mobile"]=> object(Services_Twilio_Rest_Mobile)#14 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(40) "Services_Twilio_Rest_IncomingPhoneNumber" ["client"]=> *RECURSION* ["uri"]=> string(83) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers/Mobile" } } ["instance_name"]=> string(40) "Services_Twilio_Rest_IncomingPhoneNumber" ["client"]=> *RECURSION* ["uri"]=> string(76) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/IncomingPhoneNumbers" } ["keys"]=> object(Services_Twilio_Rest_Keys)#15 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(24) "Services_Twilio_Rest_Key" ["client"]=> *RECURSION* ["uri"]=> string(60) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Keys" } ["media"]=> object(Services_Twilio_Rest_Media)#16 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(34) "Services_Twilio_Rest_MediaInstance" ["client"]=> *RECURSION* ["uri"]=> string(61) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Media" } ["messages"]=> object(Services_Twilio_Rest_Messages)#17 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(28) "Services_Twilio_Rest_Message" ["client"]=> *RECURSION* ["uri"]=> string(64) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Messages" } ["notifications"]=> object(Services_Twilio_Rest_Notifications)#18 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(33) "Services_Twilio_Rest_Notification" ["client"]=> *RECURSION* ["uri"]=> string(69) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Notifications" } ["outgoing_callerids"]=> object(Services_Twilio_Rest_OutgoingCallerIds)#19 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(37) "Services_Twilio_Rest_OutgoingCallerId" ["client"]=> *RECURSION* ["uri"]=> string(73) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/OutgoingCallerids" } ["recordings"]=> object(Services_Twilio_Rest_Recordings)#20 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(30) "Services_Twilio_Rest_Recording" ["client"]=> *RECURSION* ["uri"]=> string(66) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Recordings" } ["sms_messages"]=> object(Services_Twilio_Rest_SmsMessages)#21 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(31) "Services_Twilio_Rest_SmsMessage" ["client"]=> *RECURSION* ["uri"]=> string(68) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/SMS/Messages" } ["short_codes"]=> object(Services_Twilio_Rest_ShortCodes)#22 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(30) "Services_Twilio_Rest_ShortCode" ["client"]=> *RECURSION* ["uri"]=> string(70) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/SMS/ShortCodes" } ["tokens"]=> object(Services_Twilio_Rest_Tokens)#23 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(26) "Services_Twilio_Rest_Token" ["client"]=> *RECURSION* ["uri"]=> string(62) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Tokens" } ["transcriptions"]=> object(Services_Twilio_Rest_Transcriptions)#24 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(34) "Services_Twilio_Rest_Transcription" ["client"]=> *RECURSION* ["uri"]=> string(70) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Transcriptions" } ["connect_apps"]=> object(Services_Twilio_Rest_ConnectApps)#25 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(31) "Services_Twilio_Rest_ConnectApp" ["client"]=> *RECURSION* ["uri"]=> string(67) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/ConnectApps" } ["authorized_connect_apps"]=> object(Services_Twilio_Rest_AuthorizedConnectApps)#26 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(41) "Services_Twilio_Rest_AuthorizedConnectApp" ["client"]=> *RECURSION* ["uri"]=> string(77) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/AuthorizedConnectApps" } ["usage_records"]=> object(Services_Twilio_Rest_UsageRecords)#27 (4) { ["subresources":protected]=> array(8) { ["today"]=> object(Services_Twilio_Rest_Today)#28 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(75) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/Today" } ["yesterday"]=> object(Services_Twilio_Rest_Yesterday)#29 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(79) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/Yesterday" } ["all_time"]=> object(Services_Twilio_Rest_AllTime)#30 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(77) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/AllTime" } ["this_month"]=> object(Services_Twilio_Rest_ThisMonth)#31 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(79) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/ThisMonth" } ["last_month"]=> object(Services_Twilio_Rest_LastMonth)#32 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(79) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/LastMonth" } ["daily"]=> object(Services_Twilio_Rest_Daily)#33 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(75) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/Daily" } ["monthly"]=> object(Services_Twilio_Rest_Monthly)#34 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(77) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/Monthly" } ["yearly"]=> object(Services_Twilio_Rest_Yearly)#35 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(76) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records/Yearly" } } ["instance_name"]=> string(32) "Services_Twilio_Rest_UsageRecord" ["client"]=> *RECURSION* ["uri"]=> string(69) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Records" } ["usage_triggers"]=> object(Services_Twilio_Rest_UsageTriggers)#36 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(33) "Services_Twilio_Rest_UsageTrigger" ["client"]=> *RECURSION* ["uri"]=> string(70) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Usage/Triggers" } ["queues"]=> object(Services_Twilio_Rest_Queues)#37 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(26) "Services_Twilio_Rest_Queue" ["client"]=> *RECURSION* ["uri"]=> string(62) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Queues" } ["sip"]=> object(Services_Twilio_Rest_Sip)#38 (3) { ["subresources":protected]=> array(3) { ["domains"]=> object(Services_Twilio_Rest_Domains)#39 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(27) "Services_Twilio_Rest_Domain" ["client"]=> *RECURSION* ["uri"]=> string(67) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/SIP/Domains" } ["ip_access_control_lists"]=> object(Services_Twilio_Rest_IpAccessControlLists)#40 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(40) "Services_Twilio_Rest_IpAccessControlList" ["client"]=> *RECURSION* ["uri"]=> string(80) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/SIP/IpAccessControlLists" } ["credential_lists"]=> object(Services_Twilio_Rest_CredentialLists)#41 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(35) "Services_Twilio_Rest_CredentialList" ["client"]=> *RECURSION* ["uri"]=> string(75) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/SIP/CredentialLists" } } ["client"]=> *RECURSION* ["uri"]=> string(59) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Sip" } ["addresses"]=> object(Services_Twilio_Rest_Addresses)#42 (4) { ["subresources":protected]=> array(0) { } ["instance_name"]=> string(28) "Services_Twilio_Rest_Address" ["client"]=> *RECURSION* ["uri"]=> string(65) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Addresses" } } ["client"]=> *RECURSION* ["uri"]=> string(55) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116" ["sandbox"]=> object(Services_Twilio_Rest_Sandbox)#43 (3) { ["subresources":protected]=> array(0) { } ["client"]=> *RECURSION* ["uri"]=> string(63) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Sandbox" } ["sid"]=> string(34) "AC049b65c32bd0cad6a229b44719ac6116" } } string(99) "/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Messages/PN4dd1d27307e1ae889c716f38d54759aa" string(34) "PN4dd1d27307e1ae889c716f38d54759aa"
答案 0 :(得分:3)
我必须查看Twilio文档并对我的帐户进行一些测试。
要获取帐户中的所有邮件,您只需迭代 $ client-&gt; account-&gt;消息即可。要获取特定消息,您可以使用接受消息ID的 get()方法。
这是一个有效的例子:
$client = new Services_Twilio(TWILIO_SID, TWILIO_TOKEN);
foreach($client->account->messages as $message) {
echo "<tr><td>" . $message->from . "</td><td>" . $message->date_sent . "</td><td>" . $message->body . "</td></tr>";
}
您可以在此处阅读更多内容并查看示例:
Twilio Docs SMS Messages API Reference
如果您要过滤收到的邮件,可以使用列表过滤器:Twilio API List filter
$client = new Services_Twilio(TWILIO_SID, TWILIO_TOKEN);
$messages = $client->account->messages->getIterator(0, 50, array(
'From' => $from,
'To' => $to,
'DateSent' => $date,
));
foreach ($messages as $message) {
echo "<tr><td>" . $message->from . "</td><td>" . $message->date_sent . "</td><td>" . $message->body . "</td></tr>";
}
在您的情况下,您只能使用Т®过滤器来获取特定号码的传入消息