Last active
December 24, 2015 22:38
-
-
Save freekrai/6873774 to your computer and use it in GitHub Desktop.
Search.php for use with http://rogerstringer.com/2013/05/13/your-own-google-sms-search-with-twilio-and-php/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once 'google-api-php-client/src/Google_Client.php'; | |
| require_once 'google-api-php-client/src/contrib/Google_CustomsearchService.php'; | |
| session_start(); | |
| $client = new Google_Client(); | |
| $client->setApplicationName('My Google SMS Search Replacement'); | |
| $client->setDeveloperKey('Your Developer Key Here'); | |
| $search = new Google_CustomsearchService($client); | |
| $result = $search->cse->listCse($_POST['Body'], array( | |
| 'cx' => 'YOUR CUSTOMER SEARCH ENGINE CX HERE', | |
| 'num'=> '3', | |
| )); | |
| if( count($results['items']) ){ | |
| $msg = array(); | |
| foreach($results['items'] as $item){ | |
| $msg[] = $item['title']." ".$item['link']); | |
| } | |
| print_sms_reply( $msg ); | |
| }else{ | |
| print_sms_reply ("No matches found"); | |
| } | |
| function print_sms_reply ($sms_reply){ | |
| echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | |
| echo "<Response>\n"; | |
| if( !is_array($sms_reply) ){ | |
| echo '<Message>'.$sms_reply.'</Message>'; | |
| }else{ | |
| $cnt = count($sms_reply); | |
| $i = 1; | |
| foreach($sms_reply as $line){ | |
| $line = $line." (".$i."/".$cnt.")"; | |
| echo '<Message>'.$line.'</Message>'; | |
| $i++; | |
| } | |
| } | |
| echo "</Response>\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment