Total Users Online: 0 üye, 122 guest | Tarih/Saat: 2026-04-20 15:40
 
PHP: JSON: AJAX: Youtube Video Aramaları
2012-10-15 22:08 GMT  oklu Alnt
Kaan

User is: Online status   Gender_M
Posts: 2772
Ülke: İstanbul - 34
Meslek: Serbest Meslek
Age: 43

Youtube video arama tekni?ini (gdata json api) kullanarak basit bir ajax arama sistemi yapal?m.

Uygulamada 2 farkl? php dosyas? olu?turduk. Ana dosya (index.php) ve ajax postun cevapland??? arama (videosearch.php) dosyas? uygulaman?n ?al??mas? i?in yeterlidir.

Basit bir arama formu ile aranan kelime, jquery post methodu ile, videosearch.php dosyas?na aktar?l?r ve youtube gdata apisine g?nderilir.

index.php kodlar?n? inceleyelim:
:
tml]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Youtube JSON Video Arama</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

<script type="text/javascript">

<?php

if(isset($_GET['q'])){

?>

$.ajax({

type: 'POST',

url: 'videosearch.php',

data: 'key=<?=$_GET['q']?>',

success:function(ajaxCevap) {

$('#sonuclar').html(ajaxCevap);

}

});

<?php

}

?>

</script>

</head>

<body>

<h1>Demo</h1>

<hr />

<form method="get"><strong>Aranacak kelime:</strong> <input type="text" name="q" value="<?=$_GET['q']?>"/> <input type="submit" value="Ara" /></form>

<p>&amp;amp;amp;nbsp;</p>



<div id="sonuclar" align="center">

<?php

if(isset($_GET['q'])){

?>

<img src="fav-loader.gif" align="middle" />

<br />

<strong>Sonu?lar y?kleniyor</strong>

<?php

}else{

?>



<strong>Videolar i?in arama kutucu?unu kullan?n?z.</strong>

<?php

}

?>

</div>



<hr />



<div style="clear:both;"></div>

<br />

PHP: JSON: AJAX: Youtube Video Aramalar?</strong> yaz?s? i?in haz?rlanm??t?r.



</body>

</html>

ndex.php ile al?nan arama kelimesi, kodlarda g?rebilece?iniz gibi jquery yard?m?yla videosearch.php dosyas?na post edilir ve gelen cevap sonuclar div katman?n?n i?ine aktar?l?r.

videosearch.php kodlar?:
:
hp]<style>

html{font-family:Verdana, Geneva, sans-serif; font-size:11px;}



a{color:#009; text-decorationne;}

a img{borderne;}

</style>

<?php

$key=$_POST['key'];



function VideoSearch($searchTerms) {

$googleBaseUrl = "http://gdata.youtube.com/feeds/api/videos?q=".$searchTerms."&amp;amp;amp;format=5&amp;amp;amp;start-index=1&amp;amp;amp;max-results=20&amp;amp;amp;v=2&amp;amp;amp;alt=jsonc"; /* CURL ile ba?lan?lacak youtube gdata ba?lant?s?*/

$googleFullUrl = $googleBaseUrl;

$curlObject = curl_init();

curl_setopt($curlObject,CURLOPT_URL,$googleFullUrl);

curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);

curl_setopt($curlObject,CURLOPT_HEADER,false);

curl_setopt($curlObject,CURLOPT_REFERER,"http://www.site.com/");

$returnGoogleSearch = curl_exec($curlObject);

curl_close($curlObject);

$returnGoogleSearch = json_decode($returnGoogleSearch,true); /*json format?nda gelen cevap decode edilir*/

return $returnGoogleSearch['data']['items'];

}



$setSearchTerms = urlencode($key);

$searchResults = VideoSearch($setSearchTerms);

if(sizeof($searchResults)>0){

foreach($searchResults as $result){

?>

<div style="width:150px; float:left; padding:3px; margin:5px; height:130px; overflow:hidden;">

<a href="http://www.youtube.com/watch?v=<?=$result['id']?>" title="<?=$result['title']?>">

<img src="<?=$result['thumbnail']['sqDefault']?>" width="120" alt="<?=$result['title']?>" title="<?=$result['title']?>"/>

</a>

<p align="center">

<a href="http://www.youtube.com/watch?v=<?=$result['id']?>" title="<?=$result['title']?>">

<?=$result['title']?>

</a>

</p>

</div>

<?php

}

}

?>
Konuyla İlgili Diğer Başlıklar
Ruby - Stinge Lumina (Radio Edit) Video
Seditio Eklenti Nasıl Kurulur Video
Facebook Like URL data Extract Using jQuery PHP and Ajax
Facebook like Autosuggestion with jQuery, Ajax and PHP
Youtube'dan Ramazan'a özel hazırlık!
Emlak, Oto Galeri, Rent A Car, ?iir, Edebiyat Script Sipari?lerinizi Verebilirsiniz.
Detaylar ??in: kaan@ntka.org

Seditio 170 ?ndir
Capte M?zik ?ndir
Seditio Toolbar ?ndir

 

Powered by Seditio © 2009-2012 All Rights Reserved