Twilio:以编程方式添加/更改电话号码

Twilio: Add/Change Phonenumber programmatically

本文关键字:电话号码 添加 方式 编程 Twilio      更新时间:2023-10-25

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

这里是Twilio开发人员的传道者。

使用Twilio API提供新的电话号码需要两个步骤。首先,您需要使用available phone Numbers资源查找可用的电话号码。你可以在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;
}

其次,您需要向Incoming Phone Numbers资源请求购买该号码。

// 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实例资源更新号码。

如果这有帮助,请告诉我。