Twilio:以编程方式添加/更改Phonenumber

时间:2016-03-31 07:49:33

标签: javascript php twilio

如何使用https://www.twilio.com/user/account/voice/phone-numbers中的API以编程方式添加/编辑电话号码。

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

使用Twilio API配置新电话号码需要两个步骤。首先,您需要使用Available Phone Numbers resource查找可用的电话号码。您可以在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);

$numbers = $client->account->available_phone_numbers->getList('US', 'Local');
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}

其次,你需要制作一个request to the Incoming Phone Numbers resource to purchase that number

// choose $twilio_number from the previous response.
$number = $client->account->incoming_phone_numbers->create(array(
    "FriendlyName" => "My Company Line",
    "VoiceUrl" => "http://demo.twilio.com/docs/voice.xml",
    "PhoneNumber" => $twilio_number
));

然后,您可以使用Incoming Phone Numbers instance resource更新号码。

让我知道这是否有帮助。