├── README.md ├── bin ├── Api.php ├── Helper.php ├── Output.php └── PHPCaller.php ├── index.php └── truecaller /README.md: -------------------------------------------------------------------------------- 1 | 2 | # NOTE This is now DEPRECATED and will NOT work anymore 3 | 4 | __PHPCALLER - A PHP wrapper for the Truecaller API__ 5 | 6 | MADE WITH L<3VE BY __j0y__ <> 7 | 8 | DISCLAIMER: This was purely a hobby project with no intention of distributing or marketing this software 9 | 10 | __PHPCaller is a command line tool made in PHP to fetch data from the truecaller API__ 11 | 12 | To use the PhpCaller, first you'll need to get your "bearer ID". For that you can go to http://www.truecaller.com/ from your PC and search for any number. It will ask you to login or complete an oAuth procedure (if you haven't already logged in to their site). 13 | After the login is done open your console and paste this script (don't worry, the changes made are temporary, and it's not a malware) 14 | 15 | (function(setRequestHeader) { 16 | XMLHttpRequest.prototype.setRequestHeader = function(key, val) { 17 | if(key == "Authorization") document.write("

"+val.replace("Bearer ", "")+"

"); 18 | }; 19 | })(XMLHttpRequest.prototype.setRequestHeader); 20 | 21 | Now search for another number, and you should be able to see a code in your screen. That is your bearer ID. Copy it and run the command `php truecaller setBearer ` 22 | 23 | So if your bearer ID is `Y99Opnpg2e5_KDZpys6RRASvym7` then you should type 24 | 25 | php truecaller setBearer Y99Opnpg2e5_KDZpys6RRASvym7 26 | 27 | to set your bearer 28 | 29 | Now you're all set to go! Type, 30 | 31 | php truecaller search 32 | 33 | to get a JSON response from truecaller about the number 34 | 35 | __NOTE__ To get the response without the colour codes (for when you're calling this script from a different application or bot) just add `ignore-decoration` at the end of the command. 36 | 37 | Eg, `php truecaller search 9876543210 ignore-decoration` 38 | 39 | Example: 40 | 41 | php truecaller search 9876543210 42 | 43 | You can also type `php truecaller list` or `php truecaller help` to get a list of all commands or to read this README respectively. 44 | 45 | There is also a browser implementation of it, in `index.php`. Check the code for further implementation details or feel free too drop me a mail if you have any questions! 46 | -------------------------------------------------------------------------------- /bin/Api.php: -------------------------------------------------------------------------------- 1 | _apiBaseUrl = "https://www.truecaller.com/api/"; 9 | $this->_debug = false; 10 | $this->_headers = []; 11 | } 12 | 13 | public function debug($flag = true){ 14 | $this->_debug = $flag; 15 | return $this; 16 | } 17 | 18 | public function fetch($number = null, $countryCode = 'IN'){ 19 | $front = array( 20 | 'type' => 4, 21 | 'countryCode' => $countryCode, 22 | 'q' => $number 23 | ); 24 | $front = "search?".http_build_query($front); 25 | return $this->_sendRequest($front); 26 | } 27 | 28 | public function suggestName($number, $name){ 29 | $payload = json_encode(array(array( 30 | "p" => $number, 31 | "n" => $name, 32 | "t" => 1 33 | ))); 34 | return $this->_sendRequest("nameSuggestion", "POST", $payload); 35 | } 36 | 37 | protected function _sendRequest($front = null, $method = "GET", $params = [], $sendHeaders = true){ 38 | $url = $this->_apiBaseUrl.$front; 39 | $ch = curl_init(); 40 | curl_setopt($ch, CURLOPT_URL, $url); 41 | if($sendHeaders){ 42 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders()); 43 | } 44 | if($method === "POST"){ 45 | curl_setopt($ch, CURLOPT_POST, 1); 46 | if(count($params) > 0 && is_array($params)){ 47 | curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params)); 48 | } 49 | else if(strlen($params) > 0){ 50 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 51 | } 52 | } 53 | if($this->_debug){ 54 | curl_setopt($ch, CURLOPT_VERBOSE, true); 55 | } 56 | curl_setopt($ch, CURLOPT_HEADER, 1); 57 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 58 | $response = curl_exec($ch); 59 | $server_output = array(); 60 | $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 61 | $server_output['response_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); 62 | $server_output['header'] = substr($response, 0, $header_size); 63 | $server_output['body'] = substr($response, $header_size); 64 | curl_close ($ch); 65 | return $server_output; 66 | } 67 | 68 | public function setHeaders($headers = []){ 69 | $this->_headers = $headers; 70 | return $this; 71 | } 72 | 73 | /** 74 | * Returns all the headers to send as an array 75 | * @return (array) Headers to be sent 76 | */ 77 | protected function getHeaders(){ 78 | $headers = array(); 79 | foreach ($this->_headers as $key => $value) { 80 | $headers[] = $key.": ".$value; 81 | } 82 | return $headers; 83 | } 84 | } -------------------------------------------------------------------------------- /bin/Helper.php: -------------------------------------------------------------------------------- 1 | "Search for an account by it's number. Usage: ./truecaller search . NOTE: If country_code is left blank, by default \"IN\" will be used", 8 | "list" => "Lists all available commands", 9 | "help" => "Shows the help manual", 10 | "suggest_name" => "Suggest a new name for a number. Usage: ./truecaller suggest_name +919876543210 Walter%20White. NOTE: the number has to be along with country code and the name has to be URL encoded" 11 | ); 12 | 13 | const BEARER_FILENAME = '.bearer'; 14 | const README_FILENAME = 'README.md'; 15 | 16 | 17 | private $_newLineCharacter, $_tabCharacter; 18 | 19 | public function __construct($nl = "\n", $t = "\t"){ 20 | $this->_newLineCharacter = $nl; 21 | $this->_tabCharacter = $t; 22 | } 23 | 24 | public function showHeader(){ 25 | echo $this->_tabCharacter.Output::colorString("PHPCALLER - A PHP wrapper for the Truecaller API", "success").$this->_newLineCharacter.$this->_tabCharacter.Output::colorString("MADE WITH L").Output::colorString("<3", "error").Output::colorString("VE BY ").Output::colorString("j0y ", "success"); 26 | echo $this->_newLineCharacter.$this->_newLineCharacter.$this->_tabCharacter.Output::colorString("DISCLAIMER: ", "success").Output::colorString(" This was purely a hobby project with no intention of distributing or marketing this software"); 27 | } 28 | 29 | public function listCommands(){ 30 | foreach(self::COMMANDS as $command => $description){ 31 | echo $this->_tabCharacter.$command.$this->_tabCharacter; 32 | echo str_replace("\n", "\n".$this->_tabCharacter.$this->_tabCharacter, chunk_split(Output::colorString($description, "success"), 100)); 33 | echo $this->_newLineCharacter; 34 | } 35 | echo $this->_newLineCharacter; 36 | } 37 | 38 | public function displayManPage(){ 39 | if(!file_exists(self::README_FILENAME)){ 40 | echo "File README.md not found!"; 41 | return; 42 | } 43 | $manPage = explode("\n", file_get_contents(self::README_FILENAME)); 44 | foreach ($manPage as $line) { 45 | echo Output::colorString(chunk_split($line, 130)); 46 | } 47 | 48 | } 49 | 50 | public function setBearer($bearerId){ 51 | try{ 52 | $file = fopen(self::BEARER_FILENAME, "w+"); 53 | fwrite($file, $bearerId); 54 | fclose($file); 55 | Output::write(Output::colorString("Bearer ID set successfully", "success")); 56 | } 57 | catch(Exception $e){ 58 | Output::write(Output::colorString("Error setting bearer ID!", "error")." Reason: ".Output::colorString($e->getMessage(),"info")); 59 | } 60 | } 61 | 62 | 63 | public function getBearer(){ 64 | $this->validateBearer(); 65 | return file_get_contents(self::BEARER_FILENAME); 66 | } 67 | 68 | 69 | public function validateBearer(){ 70 | if(!file_exists(self::BEARER_FILENAME)){ 71 | Output::write(Output::colorString("ERROR: ", "error").Output::colorString("Bearer file not found! Please include bearer for authorization. Type \"php truecaller help\" for information on how to include bearer")); 72 | exit(0); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /bin/Output.php: -------------------------------------------------------------------------------- 1 | "31", 42 | 'success' => "32", 43 | 'attention' => "33", 44 | 'info' => "34", 45 | ); 46 | if(!array_key_exists($weight, $colors)){ 47 | $colors[$weight] = $weight; 48 | } 49 | return "\033[".$colors[$weight]."m".$str."\033[0m"; 50 | } 51 | } -------------------------------------------------------------------------------- /bin/PHPCaller.php: -------------------------------------------------------------------------------- 1 | _sapi = $sapi; 15 | $this->_argv = $argv; 16 | } 17 | 18 | public function run($secureMode = true){ 19 | if($this->_argv[count($this->_argv)-1] == "ignore-decoration"){ 20 | Output::$ignoreDecoration = true; 21 | Output::setNewLineCharacter(""); 22 | } 23 | else{ 24 | Output::setNewLineCharacter($this->newLineCharacter); 25 | } 26 | if($secureMode && php_sapi_name() !== $this->_sapi){ 27 | echo "Unauthorized access"; 28 | return; 29 | } 30 | 31 | if(count($this->_argv) < 2){ 32 | Output::write(Output::colorString("ILLEGAL COMMAND!", "error").$this->newLineCharacter.$this->newLineCharacter.Output::colorString("Type ", "success").Output::colorString("php truecaller list ").Output::colorString("to show a list of all available commands", "success")); 33 | return; 34 | } 35 | 36 | 37 | $helper = new Helper($this->newLineCharacter, $this->tabCharacter); 38 | $api = new Api(); 39 | switch ($this->_argv[1]) { 40 | case 'list': 41 | echo $this->newLineCharacter.$this->newLineCharacter.str_repeat("-", 150).$this->newLineCharacter.$this->newLineCharacter; 42 | $helper->showHeader(); 43 | echo $this->newLineCharacter; 44 | Output::write($this->newLineCharacter.$this->tabCharacter."LIST OF AVAILABLE COMMANDS"); 45 | $helper->listCommands(); 46 | echo str_repeat("-", 150).$this->newLineCharacter.$this->newLineCharacter; 47 | return; 48 | break; 49 | case 'help': 50 | echo $this->newLineCharacter.$this->newLineCharacter.str_repeat("-", 150).$this->newLineCharacter.$this->newLineCharacter; 51 | $helper->displayManPage(); 52 | echo $this->newLineCharacter.str_repeat("-", 150).$this->newLineCharacter.$this->newLineCharacter; 53 | return; 54 | break; 55 | case 'setBearer': 56 | if(!isset($this->_argv[2])){ 57 | Output::write(Output::colorString("Bearer ID not included")); 58 | return; 59 | } 60 | $helper->setBearer($this->_argv[2]); 61 | return; 62 | break; 63 | case 'search': 64 | if(!isset($this->_argv[2]) || !is_numeric($this->_argv[2])){ 65 | Output::write(Output::colorString("Phone number not provided or is invalid")); 66 | return; 67 | } 68 | $bearer = $helper->getBearer(); 69 | $api->setHeaders(array( 70 | "authorization" => "Bearer $bearer" 71 | )); 72 | if(isset($this->_argv[3])){ 73 | $r = $api->fetch($this->_argv[2], $this->_argv[3]); 74 | } 75 | else{ 76 | $r = $api->fetch($this->_argv[2]); 77 | } 78 | Output::write(Output::colorString($r['body'], "success")); 79 | break; 80 | case 'suggest_name': 81 | if(!isset($this->_argv[2]) || !is_numeric($this->_argv[2]) || !isset($this->_argv[3])){ 82 | Output::write(Output::colorString("Phone number or name not provided or is invalid")); 83 | return; 84 | } 85 | $bearer = $helper->getBearer(); 86 | $api->setHeaders(array( 87 | "authorization" => "Bearer $bearer", 88 | "Content-Type" => "application/json" 89 | )); 90 | $r = $api->suggestName($this->_argv[2], urldecode($this->_argv[3])); 91 | if($r['response_code'] == 200){ 92 | Output::write(Output::colorString("Your suggestion was sent", "success")); 93 | } 94 | else{ 95 | Output::write(Output::colorString($r['body'], "error")); 96 | } 97 | break; 98 | 99 | default: 100 | Output::write(Output::colorString($this->tabCharacter."ERROR: ", "error").Output::colorString("Front ").Output::colorString("\"".$this->_argv[1]."\"", "error").Output::colorString(" not found")); 101 | echo $this->tabCharacter."LIST OF AVAILABLE COMMANDS".$this->newLineCharacter.$this->newLineCharacter; 102 | $helper->listCommands(); 103 | return; 104 | } 105 | 106 | 107 | } 108 | } -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | PHPCaller 8 | 33 | 34 | 35 |

PHPCALLER - A PHP wrapper for the Truecaller API


36 |
37 |
38 | Make TrueCaller API Call 39 |
40 |
41 | 42 | 48 |
49 |
50 | 51 | 52 |
53 | 54 |
55 |
56 |
57 |
58 |
59 |

API Response

60 |
61 | 0){ 63 | $argv = array(basename(__FILE__, '.php')); 64 | if(isset($_POST['front'])){ 65 | $argv[] = $_POST['front']; 66 | } 67 | if(isset($_POST['option'])){ 68 | $argv[] = $_POST['option']; 69 | } 70 | $phpCaller = new PHPCaller('apache2handler', $argv); 71 | $phpCaller->newLineCharacter = "\n"; 72 | $phpCaller->tabCharacter = "       "; 73 | ob_start(); 74 | $phpCaller->run(false); 75 | $response = ob_get_clean(); 76 | echo str_replace("\n", "
", htmlspecialchars($response)); 77 | } 78 | ?> 79 |
80 |
81 | 82 | -------------------------------------------------------------------------------- /truecaller: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | run(true); --------------------------------------------------------------------------------