Twilio可以获得所有购买的号码

I need to use the Twilio API in PHP to get all purchased numbers on my account so that they can be used in a <select> option in a HTML form.

Example:

<select class="form-control">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</select>

Can someone show a basic example of how to do this?

Twilio developer evangelist here.

You can get the list of numbers on your account by calling the Incoming Phone Numbers list resource. This is done in PHP, using the Twilio PHP helper library, like this:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "{{ account_sid }}"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token);

// Loop over the list of numbers and echo a property for each one
foreach ($client->account->incoming_phone_numbers as $number) {
    echo $number->phone_number;
}

I'll leave it to you to turn that into the HTML output you need.

Let me know if this helps.

The Twilio API documentation is pretty thorough and provides examples of how to make most of their calls. They also provide an SDK library to make it even easier. I believe the call you're looking for is /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers (Twilio Documentation). There is an example of calling it at that page:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACdc5f132a3c49700934481addd5ce1659"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token);

// Loop over the list of numbers and echo a property for each one
foreach ($client->account->incoming_phone_numbers as $number) {
    echo $number->phone_number;
}

You will need to get the "twilio-php" library, which can also be found on their site, or here.