简体   繁体   中英

retrieve SMS history from Twilio API from specific number

using twilio, trying to return a list of text messages sent to a specific number...with no luck

foreach ( $client->account->sms_messages->To(+12345678901) as $sms ) {  echo $sms->body;    echo "</br>"; }

the problem is obviously the "To(+12345678901)"

I have tried using single and double quotes, numbers owned and not owned, and several other parameter formatting options, I cant seem to get lucky here. Please help.

Twilio Developer Evangelist here.

You've almost got it. The part you're missing is using the getIterator method for filtering. You pass this an array containing the data you're filtering on. Here's a code snippet:

foreach ($client->account->messages->getIterator(0, 50, array(
    'To' => '+12345678901',
)) as $message) {
    echo "From: {$message->from}\nTo: {$message->to}\nBody: " . $message->body;
}

You can read a bit more about filtering messages in our docs. The docs for our PHP helper library also have some good examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM