2016-08-29 3 views
1

내 TWILIO 컬 쿼리가 국가 코드와 전화 번호로 어떤 아이디어도 반환하지 않는 것 같습니까? 테스트 페이지에서 고급 결과였다 통해 twilio php curl 반송하지 않음

나는 캐리어를 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'문자를 반환하면 거짓으로 간주되어 거짓 긍정을 유발합니다. 대신 boolean false,'if ($ err === false)'를 명시 적으로 테스트해야합니다. 웹 사이트가 PHP 부울 false를 반환하는 것은 불가능합니다. 텍스트 만 반환 할 수 있습니다. –

답변

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