Twilio获取所有购买的号码



我需要在PHP中使用Twilio API来获取我帐户上所有购买的号码,以便它们可以在HTML表单的<select>选项中使用。

例:

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

有人可以展示如何做到这一点的基本示例吗?

Twilio API 文档非常全面,并提供了如何进行大部分调用的示例。它们还提供 SDK 库,使其更加容易。我相信您正在寻找的电话是/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers(Twilio 文档)。在该页面上有一个调用它的示例:

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

您需要获取"twilio-php"库,该库也可以在他们的网站上或此处找到。

Twilio开发者布道者在这里。

可以通过调用传入电话号码列表资源来获取帐户上的号码列表。这是在 PHP 中完成的,使用 Twilio PHP 辅助程序库,如下所示:

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

我会把它留给你,把它变成你需要的HTML输出。

让我知道这是否有帮助。

我已经这样做了:

$twilio=new Client(TWILIO_ACC_ID,TWILIO_AUTH_TOKEN);
//get all the phone numbers on account (assuming there won't be more than 1000)
$incoming_phone_numbers=$twilio->incomingPhoneNumbers->read([],1000);
//loop through all numbers
foreach ($incoming_phone_numbers as $number) {
    print("<p>sid: ".$number->sid." phone number: ".$number->phoneNumber."</p>");
}   

与其他两个发布的内容大不相同! 我尝试了这些,但它们并没有接近工作。 也许我有不同版本的 API 或 php 库。

Twilio的文档也说要使用$number->phone_number但这显然是错误的。 它肯定会回来$number->phoneNumber

最新更新