Click Here Trigger


PHP กับ Twitter ดึงรูปภาพ Avatar ของ Follows มาโชว์

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

มีบางท่าน e-mail มาถามผมว่าหากเขียน PHP กับ Twitter แล้วนอกจากดึง Timeline และ Tweet ตอบกลับได้แล้ว สามารถโชว์ Avatars ของเพื่อนๆ ที่เป็น Followers ของเราได้หรือไม่คำตอบคือได้ครับ เราสามารถดึง Avartars ของเพื่อนเราทั้งหมดมาโชว์ได้่เลยทันทีด้วย Code ชุดต่อไปนี้

How to show the avatars of your twitter followers on your website

 

ทำการ Copy Code PHP ด้านล่างแล้วใส่ Username และ Password ของคุณที่ช่องที่ผมระบุไว้ให้ แล้ว FTP ขึ้้นไปคุณก็จะเห็นผลลัพท์

 

<?php
$username = "User Twitter ของคุณ";
$login = "Usernameของคุณ:Passwordของคุณ";

$target = "http://twitter.com/statuses/followers/"
.$username.".xml";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_USERPWD, $login);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$gettwit = curl_exec($ch);

$twitters = new SimpleXMLElement($gettwit);
$following = count($twitters);
if ($following >2) {
}
## Printing/Dumping the data
foreach ($twitters->user as $twit) {
echo "<img class="twitter_followers"
src="",
$twit->profile_image_url,
"" title=""
, $twit->name, "" alt=""
style="width:48px; height:48px;"
 />n"
;
}
curl_close($ch);
?>


ตัวอย่างเป็นยังไงก็ลองไปดุที่หน้านี้เลยครับผม Upload ให้ดูกันแล้ว

http://www.daydev.com/programming-language/
php/twitter-api-avatar-php.html

หมายเหตุ: ล่าสุด code ชุเดนี้กำลังจะเขียนเป็น Component และ Module ของ Joomla ครับไว้เร็วๆจะบอกอีกทีวันนี้ก้ลาล่ะครับ

Contributors: Banyapon Poolsawasd


Social Media Marketing และที่ปรึกษาด้านการตลาดออนไลน์ มีงานวิจัยด้านนวัตกรรมออนไลน์ และโครงงานด้านเทคโนโลยี Social Integration และ Augmented Reality ร่วมทั้งในประเทศ และต่างประเทศ รวมถึงตำแหน่งอาจารย์พิเศษ ประจำมหาวิทยาลัยชั้นนำ และวิทยากรพิเศษ นักวิจัย นักคิด

Comments

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins
Press Esc to close