2016-08-29 3 views
1

TWILIOのカールクエリーは、国コードと電話番号以外に何かアイデアを返してくれないようですか?twilio php curl not carrierを返す

キャリアは私のテストページから細かい 結果ましたスルー来るtwilio私は上のルックアップ:

no curl error 

stdClass Object 
(
    [caller_name] => 
    [country_code] => US 
    [phone_number] => +1201832xxxx 
    [national_format] => (201) 832-xxxx 
    [carrier] => 
    [add_ons] => 
    [url] => https://lookups.twilio.com/v1/PhoneNumbers/+1201832xxxx 
) 

caller_name is 
caller_name is 
caller_type is 
error_code is 
country_code is US 
phone number is +1201832xxxx 
national_format (201) 832-xxxx 
Carrier name is 
Carrier name is 
Carrier type is 
error_code is 
mobile_network_code 
mobile_country_code is 
no curl error 

コードが

$cSession =  curl_init("https://lookups.twilio.com/v1/PhoneNumbers/+1201832xxxx"); 

curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($cSession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 

curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'GET'); 
curl_setopt($cSession, CURLOPT_POSTFIELDS, "Type=carrier"); 

curl_setopt($cSession, CURLOPT_USERPWD, "xxxxxxx:xxxxxxx"); 


$response   =  curl_exec($cSession); 

$err = curl_error($cSession); 

if ($err) { 
    echo "cURL Error #:" . $err."<br/>"; 
} else { 
echo "no curl error<br/>"; 

} 

$response   =  json_decode($response); 

echo "<pre>"; print_r($response); echo "</pre><br/>"; 
echo "caller_name is ".$response->caller_name."<br/>"; 
echo "caller_name is ".$response->caller_name->caller_name."<br/>"; 
echo "caller_type is ".$response->caller_name->caller_type."<br/>"; 
echo "error_code is ".$response->caller_name->error_code."<br/>"; 
echo "country_code is ".$response->country_code."<br/>";  
echo "phone number is ".$response->phone_number."<br/>"; 

echo "national_format ".$response->national_format."<br/>"; 
echo "Carrier name is ".$response->carrier."<br/>"; 
echo "Carrier name is ".$response->carrier->name."<br/>"; 
echo "Carrier type is ".$response->carrier->type."<br/>"; 
echo "error_code is ".$response->carrier->error_code."<br/>"; 
echo "mobile_network_code ".$response->carrier->mobile_network_code."<br/>"; 
echo "mobile_country_code is ".$response->carrier->mobile_country_code."<br/>"; 
+0

'if($ err)'が有効なテストではない。あなたが擦っているサイトが空の文字列または '0'文字を返すと、それもfalseとカウントされ、false-positiveを引き起こします。 boolean false、 'if($ err === false)'を明示的にテストする必要があります。ウェブサイトがphp boolean falseを返すことはできません。 TEXTのみを返すことができます。 –

答えて

0

を下回っている私は、xget command posted on twilioを使用して代わりにもしくはshell_execを使用し、私が得ました私が必要とした回答

$cmd="curl -XGET 'https://lookups.twilio.com/v1/PhoneNumbers/+1201832xxxx?Type=carrier&Type=caller-name' -u 'clientidxxxxxx:clienttokenxxxxxx' "; 
$result=shell_exec($cmd); 

$response   =  json_decode($result); 

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

これはこれを行う方法ではありません。 Twilioは、データを操作するための素晴らしいライブラリを提供します。投稿したリンクで参照されているライブラリを使用していないのはなぜですか? – WillardSolutions