How to transfer Twilio lookup cURL code to PHP cURL
Just use CURLOPT_USERPWD
option
$ch = curl_init("https://lookups.twilio.com/v1/PhoneNumbers/(919)%20410-7522");curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');curl_setopt($ch, CURLOPT_POSTFIELDS, "Type=carrier");curl_setopt($ch, CURLOPT_USERPWD, "{AccountSid}:{AuthToken}");$response = curl_exec($ch);
<?phpecho time()."<br/>";$cmd="curl -XGET 'https://lookups.twilio.com/v1/PhoneNumbers/+19999999999?Type=carrier&Type=caller-name' -u 'YOURUSERACCOUNT:YOURAUTHTOKEN' ";$result=shell_exec($cmd);$response = json_decode($result);echo "country_code is ".$response->country_code."<br/>"; echo "<pre>"; print_r($response); echo "</pre><br/>";echo "country_code is ".$response->country_code."<br/><br/>";echo "phone number is ".$response->phone_number."<br/>";echo "national_format ".$response->national_format."<br/><br/>";$carrier=json_decode($response->carrier); echo "Carrier name is ".$response->carrier->name."<br/>";echo "Carrier type is ".$response->carrier->type."<br/>";echo "Carrier error_code is ".$response->carrier->error_code."<br/>";echo "Carrier mobile_network_code ".$response->carrier->mobile_network_code."<br/>";echo "Carrier mobile_country_code is ".$response->carrier->mobile_country_code."<br/><br/>";$caller_name=json_decode($response->caller_name);echo "caller_name is ".$response->caller_name->caller_name."<br/>";echo "caller_name error_code is ".$response->caller_name->error_code."<br/>";?> enter code here
I wasnt getting the carrier response so i changed to shell_exec using the curl xget command listed on twilio and it worked fine