Twitter Arama Sonuçlarını Çekme
Merhaba arkadaşlar,
Bugün sizlere Twitter’daki arama sonuçlarını PHP ile nasıl çekeceğinizi anlatıyorum.
Twitter
API’sini kullanacağız bu verileri çekerken. Verileri JSON formatında
alacağız ve onları işleyeceğiz. Twitter’ın search API’si için daha
detaylı bilgi için buraya tıklayınız.
Öncelikle
PHP fonksiyonumuzu hazırlayalım. Bu fonksiyonu Twitter’da arama sonucu
varsa sonuçları döndürecek eğer sonuç yoksa false dönecek şekilde
hazırladım.
function twitterSonuclari($data){ $t_search = file_get_contents("http://search.twitter.com/search.json?q=".urldecode($data)."&result_type=recent&rpp=10"); $results = json_decode($t_search, true); if(count($results["results"])>0){ return $results["results"]; } else{ return false; } }
Eğer fonksiyon sonuç bulursa bir dizi döndürür. Bu dizi aşağıdaki gibidir:
Array ( [0] => Array ( [created_at] => Fri, 26 Aug 2011 00:52:37 +0000 [from_user] => oralunal [from_user_id] => 229123064 [from_user_id_str] => 229123064 [geo] => [id] => 106891765147115520 [id_str] => 106891765147115520 [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/1435376616/MYDC2013_normal.JPG 1 => <a rel="nofollow" href="http://bit.ly">bitly</a> 1 => http://t.co/zweOT0v http://t.co/gjodqyw [to_user_id] => [to_user_id_str] => ) [1] => Array ( [created_at] => Thu, 25 Aug 2011 23:56:56 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106877753726484481 [id_str] => 106877753726484481 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Her Kadın Güzeldir http://togl.me/F1 #forum [to_user_id] => [to_user_id_str] => ) [2] => Array ( [created_at] => Thu, 25 Aug 2011 22:13:47 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106851795116113921 [id_str] => 106851795116113921 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Diyet bilgileri ve diyet haberleri http://togl.me/9B1 #forum [to_user_id] => [to_user_id_str] => ) [3] => Array ( [created_at] => Thu, 25 Aug 2011 20:47:40 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106830120425226240 [id_str] => 106830120425226240 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Çeşme tatil yerleri http://togl.me/b9A #forum [to_user_id] => [to_user_id_str] => ) [4] => Array ( [created_at] => Thu, 25 Aug 2011 17:00:54 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106773053723250689 [id_str] => 106773053723250689 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Kuşadası Otelleri http://togl.me/6e8 #forum [to_user_id] => [to_user_id_str] => ) [5] => Array ( [created_at] => Thu, 25 Aug 2011 17:00:53 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106773051965849600 [id_str] => 106773051965849600 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Marmaris Otelleri http://togl.me/A50 #forum [to_user_id] => [to_user_id_str] => ) [6] => Array ( [created_at] => Thu, 25 Aug 2011 17:00:53 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106773049973547008 [id_str] => 106773049973547008 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Bayram Turları http://togl.me/4F1 #forum [to_user_id] => [to_user_id_str] => ) [7] => Array ( [created_at] => Thu, 25 Aug 2011 15:35:54 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106751663645270016 [id_str] => 106751663645270016 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Ayvalık Otelleri http://togl.me/06C #forum [to_user_id] => [to_user_id_str] => ) [8] => Array ( [created_at] => Thu, 25 Aug 2011 15:35:54 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106751661783003137 [id_str] => 106751661783003137 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Ucuz Tatil oteli http://togl.me/4f3 #forum [to_user_id] => [to_user_id_str] => ) [9] => Array ( [created_at] => Thu, 25 Aug 2011 14:29:06 +0000 [from_user] => trkodlama [from_user_id] => 8982188 [from_user_id_str] => 8982188 [geo] => [id] => 106734854372212736 [id_str] => 106734854372212736 [iso_language_code] => tr [metadata] => Array ( [result_type] => recent ) [profile_image_url] => http://a2.twimg.com/profile_images/349223586/trkodlama_normal.png 1 => <a rel="nofollow" href="http://twitterfeed.com">twitterfeed</a> 1 => Forumdan: Bayram Tatili Otelleri http://togl.me/4d3 #forum [to_user_id] => [to_user_id_str] => ) )
Şimdi kontrol edip işleme sayfasına geçelim:$arama = "trkodlama"; if(($results = twitterSonuclari($arama))!=FALSE){ foreach($results AS $r){ echo $r['from_user']; // tiviti atan kullanıcı echo $r['profile_image_url']; // tiviti atan kullanıcının resmi echo $r['text']; // Atılan tivit }
Kullanımı kolay ve basit bir API. Kolay gelsin.
Yorumlar
Yorum Gönder