如何使用Twilio的运营商查询来访问电话运营商?
以下是我的一些示例代码:
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;
答案 0 :(得分:3)
Twilio开发者传道者在这里。
当您呼叫承运人详细信息时,它们都将作为对象返回到名为carrier
的号码上。您可以在Twilio Lookup页面上的示例响应中看到此信息。所以,使用您的代码:
$number = $client->phone_numbers->get("5555555555", array("CountryCode" => "US", "Type" => "carrier"));
echo $number->carrier->name;
echo $number->carrier->type;
答案 1 :(得分:2)
使用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。
答案 2 :(得分:0)
获取"键入" => "来电者姓名",响应可以解除:
echo $response->callerName["caller_name"];
camelCase,连字符和破折号都在一个用例中!