Skip to content

Instantly share code, notes, and snippets.

@freekrai
Last active December 24, 2015 22:38
Show Gist options
  • Select an option

  • Save freekrai/6873774 to your computer and use it in GitHub Desktop.

Select an option

Save freekrai/6873774 to your computer and use it in GitHub Desktop.
<?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