$htmlBody = <<
Search Term:
Max Results:
END;
if ($_GET['q'] && $_GET['maxResults']) {
// Call set_include_path() as needed to point to your client library.
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_YouTubeService.php';
/* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
Google APIs Console
Please ensure that you have enabled the YouTube Data API for your project. */
$DEVELOPER_KEY = 'put your api key here';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new Google_YoutubeService($client);
try {
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));
$videos = '';
$channels = '';
$playlists = '';
//print_r($searchResponse['items']);
for($x=0;$x
echo $searchResponse['items'][$x]['id'] ['videoId'] ;
}
/*
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('
$searchResult['id']['videoId']);
break;
case 'youtube#channel':
$channels .= sprintf('
$searchResult['id']['channelId']);
break;
case 'youtube#playlist':
$playlists .= sprintf('
$searchResult['id']['playlistId']);
break;
}
}
$htmlBody .= <<
Videos
- $videos
Channels
- $channels
Playlists
- $playlists
END;*/
} catch (Google_ServiceException $e) {
$htmlBody .= sprintf('A service error occurred:
%s
',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('An client error occurred:
%s
',
htmlspecialchars($e->getMessage()));
}
}
?>
=================================================================
Google Image Search:
$url = "https://ajax.googleapis.com/
"v=1.0&q=barack%20obama&
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://localhost/#######/google.php");
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$json = json_decode($body);
/*$results = array();
foreach ($json['responseData']['
$results[] = array(
'url' => $result['url'],
'title' => $result['title'],
'content'=>$result['content']
);
}
*/
echo '
'; var_dump($json->responseData->';results); echo '
for($x=0;$x
echo "Result ".($x+1)."";
echo "
Image: ";
echo $json->responseData->results[$
echo "
echo $json->responseData->results[$
echo "
URL: ";
echo $json->responseData->results[$
echo "
VisibleURL: ";
echo $json->responseData->results[$
echo "
Title: ";
echo $json->responseData->results[$
echo "
Content: ";
echo $json->responseData->results[$
echo "
";
}
// now have some fun with the results...
/*echo '
'; var_dump($json); echo '';
*/
//$decodedJSON = json_encode($json);
// Put everyting to the screen with var_dump;
//var_dump($decodedJSON);
// With print_r ( useful for arrays );
//print_r($decodedJSON);
/*foreach ( $json->responseData->results as $results1 )
{
echo $results1;
}*/
//print_r($json->responseData-
/*$properties = get_object_vars($json);
print_r($properties);*/
//print_r($json);
?>
==================================================================
Metacafe:
if(isset($_POST['search']))
{
$video=$_POST['video'];
//echo $video;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.metacafe.com/
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);
$result = curl_exec($curl); curl_close($curl);
//echo $result;
//$value=preg_match_all('/<
preg_match('/
print_r($matches);
}
?>
http://www.w3.org/TR/xhtml1/
">
http://www.w3.org/1999/
==================================================================
Daily Motion:
$url="https://api.dailymotion.
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://localhost/jothirajan/// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$json = json_decode($body);
/*echo '
*/
for($x=0;$x'; var_dump($json); echo '';
*/
echo "Result ".($x+1)."";
id: ";
echo $json->list[$x]->id;
echo "
Img: ";
echo "
";
echo "
channel: ";
echo $json->list[$x]->channel;
echo "
title: ";
echo $json->list[$x]->title;
echo "
";
}
?>
No comments:
Post a Comment