PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How to get countries where twilio numbers are available to buy using PHP library

 November 19, 2022     twilio, twilio-php     No comments   

Issue

Twilio documentation provides one example of searching numbers where they search for local numbers in US.

$client = new Services_Twilio($sid, $token);
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
    "InRegion" => "AR"
));
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}

Is there a way I can get all the countries where twilio numbers are available ? So I can search a number in one of those countries. Thanks


Solution

I managed to get the list of countries where twilio numbers are available

public function getAvailableCountries(){

    $client = new \Services_Twilio($this->sid, $this->token);

    $uri = '/'. $client->getVersion() . '/Accounts/' . $this->sid . '/AvailablePhoneNumbers.json';

    try{
        $numbers = $client->retrieveData($uri);

        //returns an array of countries where twilio numbers are supported
        return $numbers->countries;

    }catch(Exception $e){
        return $e->getMessage();
    }
}


Answered By - Ashfaq Ahmed
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing