Tapan sarkar
Tapan sarkar

Reputation: 47

How to know a phone type?

I am using the following code to query the type of a phone. I am using php as a language for this project only. I am using the following code.

I am only getting the phone "+12252763867" as output.from the following code

$number->phone_number; 

The question is How do I get the type of the phone?

<?php
require "NewServices/Twilio.php";
$AccountSid ="xxx" ;
$AuthToken ="xxxx" ;
$from = '<twilio phone>';
$to = '+12252763867';

$client1 = new Services_Twilio($AccountSid, $AuthToken);
$client = new Lookups_Services_Twilio($AccountSid, $AuthToken);


$number = $client->phone_numbers->get("+12252763867");
$body = $number->phone_number;

try
{
  $client1->account->sms_messages->create($from,$to,$body);
} catch (Services_Twilio_RestException $e) {

}

?>

Upvotes: 1

Views: 707

Answers (1)

philnash
philnash

Reputation: 73027

Twilio developer evangelist here.

Once you have the phone number looked up as you showed here:

$number = $client->phone_numbers->get("+12252763867");
$body = $number->phone_number;

You can query other fields on that number too, like:

$country = $number->country_code
$format  = $number->national_format

If you want more information, you can pass the Type parameter as "carrier":

$number = $client->phone_numbers->get("+12252763867", array("Type" => "carrier"))

You can then get the type of number you are asking about.

$type = $number->carrier->type

Carrier information costs $0.005 per phone number looked up.

Upvotes: 1

Related Questions