PHP

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

มีบางท่าน 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 ให้ดูกันแล้ว

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

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

Asst. Prof. Banyapon Poolsawas

อาจารย์ประจำสาขาวิชาการออกแบบเชิงโต้ตอบ และการพัฒนาเกม วิทยาลัยครีเอทีฟดีไซน์ & เอ็นเตอร์เทนเมนต์เทคโนโลยี มหาวิทยาลัยธุรกิจบัณฑิตย์ ผู้ก่อตั้ง บริษัท Daydev Co., Ltd, (เดย์เดฟ จำกัด)

Related Articles

Leave a Reply

Back to top button
Game & Mobile Development AR VR XR
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Adblock Detected

เราตรวจพบว่าคุณใช้ Adblock บนบราวเซอร์ของคุณ,กรุณาปิดระบบ Adblock ก่อนเข้าอ่าน Content ของเรานะครับ, ถือว่าช่วยเหลือกัน