twitter php Followers Counter - ตัวนับ

พูดคุยเกี่ยวกับ twitter

twitter php Followers Counter - ตัวนับ

โพสต์โดย admin » จันทร์ เม.ย. 26, 2010 10:08 pm

twitter php Followers Counter - ตัวนับสำหรับ Twitter

Function การใช้งานคือ

โค้ด: เลือกทั้งหมด
/**
* Fetch the number of followers from twitter api
*
* @author Peter Ivanov <peter@ooyes.net>
* @copyright    http://www.ooyes.net
* @version    0.2
* @link http://www.ooyes.net
* @param string $username
* @return string
*/
function twitter_followers_counter($username) {
   
   $cache_file = CACHEDIR . 'twitter_followers_counter_' . md5 ( $username );
   
   if (is_file ( $cache_file ) == false) {
      $cache_file_time = strtotime ( '1984-01-11 07:15' );
   } else {
      $cache_file_time = filemtime ( $cache_file );
   }
   
   $now = strtotime ( date ( 'Y-m-d H:i:s' ) );
   $api_call = $cache_file_time;
   $difference = $now - $api_call;
   $api_time_seconds = 1800;
   
   if ($difference >= $api_time_seconds) {
      $api_page = 'http://twitter.com/users/show/' . $username;
      $xml = file_get_contents ( $api_page );
      
      $profile = new SimpleXMLElement ( $xml );
      $count = $profile->followers_count;
      if (is_file ( $cache_file ) == true) {
         unlink ( $cache_file );
      }
      touch ( $cache_file );
      file_put_contents ( $cache_file, strval ( $count ) );
      return strval ( $count );
   } else {
      $count = file_get_contents ( $cache_file );
      return strval ( $count );
   }
}


วิธีการใช้
โค้ด: เลือกทั้งหมด
twitter_followers_counter("twitter_username");


ตัวอย่างอยู่ด้านล่างของเว็บในหน้าแรกครับ
admin
Site Admin
 
โพสต์: 196
ลงทะเบียนเมื่อ: เสาร์ มี.ค. 20, 2010 11:32 pm

ย้อนกลับไปยัง twitter

 


  • กระทู้ที่คล้ายกับ
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

กำลังดูบอร์ดนี้: ไม่มีสมาชิก และ บุคคลทั่วไป 0 ท่าน

cron