2016-12-17 7 views
2

Twillioは、電話番号を検索するときにプライベートプロパティが割り当てられたオブジェクトを返します。右下の私は、これは私がtwillio電話番号検索sdk5x

object(Twilio\Rest\Lookups\V1\PhoneNumberInstance)#23 (4) { 
    ["properties":protected]=> 
    array(6) { 
    ["callerName"]=> 
    NULL 
    ["countryCode"]=> 
    string(2) "LK" 
    ["phoneNumber"]=> 
    string(12) "+94xxxxxxxx" 
    ["nationalFormat"]=> 
    string(12) "xxxxxxxxxx" 
    ["carrier"]=> 
    NULL 
    ["addOns"]=> 
    NULL 
    } 
    ["solution":protected]=> 
    array(1) { 
    ["phoneNumber"]=> 
    string(11) "94xxxxxxxxx" 
    } 
} 

を取得していた結果の断片である

function isValidNumber($number) { 
    try{ 
     $obj = $this->client->lookups->phoneNumbers($number)->fetch(); 
     return $obj; 
    }catch(Twilio\Exceptions\RestException $e){ 
     return false; 
    } 
} 

を使用するコードは、にphoneNumberキーを取得するためのエレガントな方法はありますか?また、tryキャッチは、無効なエントリが入るとすぐに、どちらも助けてくれないように見えますが、例外はどこにでもあります。私はSDK 5xを使用しています

答えて

0

誰かが例の欠如のために立ち往生し、それほど有用なドキュメントではない場合、私は本当に簡単なものを考え出しました。これはまったくエレガントではありませんが、今のところ仕事が得られます

file_get_contents('https://'.$sid.':'.$auth_token.'@lookups.twilio.com/v1/PhoneNumbers/'.urlencode($number)); 
+0

何らかの理由であなたがcURLなしで除外されている場合は、これが実際に動作します。 –