首页 文章

如何用Twilio PHP SDK删除电话号码?

提问于
浏览
2

我正在使用Twilio PHP SDK . 我有一个电话号码的sid . 我该如何删除它?

其余的API文档显示了删除方法,但没有代码 .

https://www.twilio.com/docs/api/rest/incoming-phone-numbers#list

我在Stack Overflow上看过一些例子,但他们似乎都在使用旧版本的SDK .

1 回答

  • 2

    灵感来自:https://www.twilio.com/docs/api/rest/incoming-phone-numbers?code-sample=code-get-an-incomingphonenumber&code-language=php&code-sdk-version=5.x

    示例代码为 delete() a Twilio电话号码:

    <?php
    // Get the PHP helper library from twilio.com/docs/php/install
    require_once '/path/to/vendor/autoload.php'; // Loads the library
    use Twilio\Rest\Client;
    
    // Your Account Sid and Auth Token from twilio.com/user/account
    $sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    $token = "your_auth_token";
    $client = new Client($sid, $token);
    
    // Delete a Twilio number based on its sid. If you do not have a sid,
    // check out the list resource examples on this page
    $number = $client
        ->incomingPhoneNumbers("PN2a0747eba6abf96b7e3c3ff0b4530f6e")
        ->delete();
    

    WarningOnce the number is deleted, any code using it, won't work. Be sure you really want to run the code above.

相关问题