Twilio - 运营商查询

Twilio - Carrier Lookup

如何使用 Twilio 的运营商查找访问 phone 运营商?

这是我的一些示例代码:

require_once('twilio/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "--------------";
$token = "------------------";
$client = new Lookups_Services_Twilio($sid, $token);



$number = $client->phone_numbers->get("5555555555", array("CountryCode" => "US", "Type" => "carrier"));

//How do I access the carrier here?
    echo $number->phone_number;

这里是 Twilio 开发人员布道者。

当您致电询问承运人详细信息时,它们都会作为一个对象返回到名为 carrier 的号码上。您可以在 Twilio Lookup 页面的示例响应中看到这一点。因此,使用您的代码:

$number = $client->phone_numbers->get("5555555555", array("CountryCode" => "US", "Type" => "carrier"));

echo $number->carrier->name;
echo $number->carrier->type;

使用 Twilio 5.x SDK,情况发生了细微变化:

use Twilio\Rest\Client as Twilio;

$client = new Twilio("sid", "token");
$response = $client->lookups->phoneNumbers("+15551234567")->fetch(["type" => "carrier"]);
echo $response->carrier["type"] . "\r\n";
echo $response->carrier["name"];

有关完整的当前文档,请参阅 https://www.twilio.com/docs/api/lookups

当获取 "type" => "caller-name" 时,可以通过以下方式展开响应:

echo $response->callerName["caller_name"];

驼峰式大小写、连字符和破折号都在一个用例中!