簡體   English   中英

Twilio 獲取帳戶上所有購買的號碼

[英]Twilio get all purchased numbers on account

我需要使用 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}/IncomingPhoneNumbersTwilio 文檔)。 有一個在該頁面調用它的示例:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM