Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twilio lookup API not working?

I'm trying to use Twilio's Lookup API to get certain properties of a mobile number via PHP... with very little success:

    $twilioClient = new Lookups_Services_Twilio(Credential::TwilioSID, Credential::TwilioToken);
    $number = $twilioClient->phone_numbers->get($someNumber);

Note that this is the example code present within their 'Getting Started' page here.

By taking a look at $number in the debugger, I can confirm it is returning something:

enter image description here

The highlighted property of the object is simply recursive with no new information.

Attempting to evaluate $number->phone_number returns null. I have tried this with perhaps half a dozen completely valid numbers now and this is the only response I get.

Attempting to json_encode($number) returns false.

I have no idea why this is not working, but it'd be helpful if I could know what I'm doing wrong.

like image 203
marked-down Avatar asked Jul 11 '15 08:07

marked-down


People also ask

What is Lookup in Twilio?

Given a phone number, Twilio Lookup can identify the number's carrier and what type of phone it is (landline, mobile, or VoIP). In the U.S., Lookup can also retrieve the name of the person or business associated with a phone number (if available).

What is Lookup API?

The Lookup API lets your client applications send requests to the Safe Browsing servers to check if URLs are included on any of the Safe Browsing lists. If a URL is found on one or more lists, the matching information is returned.

How can I find out who a Twilio number belongs to?

Text +1 (855) 747-7626* with a phone number to check if it is from Twilio. That's +1 (855) 747-ROBO. If you're getting spam calls or texts from a Twilio number, this text hotline will help you report it. Learn more about this and what we're doing to stop spam on our platform.

What carrier is Twilio?

Twilio's US short codes can deliver SMS messages to the following mobile phone carriers in the United States: Major carriers: AT&T, Verizon Wireless, Sprint, and T-Mobile USA.


2 Answers

I would have been also not successful with their code defined so i used CURL to grab their API methods and it worked like a charm for me, you can try following code to get you need

    $base_url           =       "https://lookups.twilio.com/v1/PhoneNumbers/+1XXXXXXXXXX";
    $ch             =       curl_init($base_url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$account_sid:$auth_token");

$response           =       curl_exec($ch);
$response           =       json_decode($response);

echo "<pre>";   print_r($response); echo "</pre>";

It will return you few parameters (country_code, national_format, carrier)

like image 192
Naveed Metlo Avatar answered Sep 27 '22 15:09

Naveed Metlo


I'm just gonna go ahead and assume the phone numbers you've tried are neither from the US, nor in international format.

From Twilio's Lookups Quickstart Tutorial:

You'll want to include the country code of the phone number that you would like formatted. If not included, the country code will default to the US.

So your lookup should probably look like:

$number = $twilioClient->phone_numbers->get($someNumber, array('CountryCode' => 'NZ'));

If the phone numbers are from the US, in international format, or if the above still does not work, try whether the lookup succeeds on Twilio's web interface (you'll need the international prefix there).

If it does, your software library might be broken or your Twilio account might have incorrect/broken access rights.

If the web lookup fails as well, you should contact Twilio and report the issue.

like image 32
Siguza Avatar answered Sep 27 '22 16:09

Siguza