web开发 Django开发交流群:19525555 注册 | 登陆

不翻墙,让博客显示Twitter

前提:你的博客主机在国外!
说明: Twitter 的JavaScript调用, 如果浏览者没有翻墙,还是看不到内容的.我的博客主机刚好在国外.于是就想了这个办法
利用国外的服务器先读取出Twitter数据,再返回给浏览者

现在只想把内容显示出来.所有没有仔细去看 Twitter的API文档!

这里用的的接口函数是 http://twitter.com/statuses/user_timeline.xml?id=hzw513

函数是 :user_timeline  ,后面xml是你需要的格式,其他的可用格式为 JSON、Atom 和 RSS

这个默认就返回用户名为 hzw513 的最新20条数据,

XML/HTML代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <statuses type="array">  
  3. <status>  
  4.   <created_at>Wed Sep 09 05:36:42 +0000 2009</created_at>  
  5.   <id>3857923194</id>  
  6.   <text>twitter 读取数据国外服务器测试成功!</text>  
  7.   <source><a href="http://itweet.net/" rel="nofollow">iTweet</a></source>  
  8.   <truncated>false</truncated>  
  9.   <in_reply_to_status_id></in_reply_to_status_id>  
  10.   <in_reply_to_user_id></in_reply_to_user_id>  
  11.   <favorited>false</favorited>  
  12.   <in_reply_to_screen_name></in_reply_to_screen_name>  
  13.   <user>  
  14.     <id>68650526</id>  
  15.     <name>BB</name>  
  16.     <screen_name>hzw513</screen_name>  
  17.     <location></location>  
  18.     <description>What i am writting is not Twitter , but loneliness!</description>  
  19.     <profile_image_url>http://s.twimg.com/a/1252448032/images/default_profile_normal.png</profile_image_url>  
  20.     <url>http://www.hzw513.com</url>  
  21.     <protected>false</protected>  
  22.     <followers_count>2</followers_count>  
  23.     <profile_background_color>9ae4e8</profile_background_color>  
  24.     <profile_text_color>000000</profile_text_color>  
  25.     <profile_link_color>0000ff</profile_link_color>  
  26.     <profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>  
  27.     <profile_sidebar_border_color>87bc44</profile_sidebar_border_color>  
  28.     <friends_count>0</friends_count>  
  29.     <created_at>Tue Aug 25 09:14:25 +0000 2009</created_at>  
  30.     <favourites_count>0</favourites_count>  
  31.     <utc_offset>28800</utc_offset>  
  32.     <time_zone>Beijing</time_zone>  
  33.     <profile_background_image_url>http://s.twimg.com/a/1252448032/images/themes/theme1/bg.gif</profile_background_image_url>  
  34.     <profile_background_tile>false</profile_background_tile>  
  35.     <statuses_count>19</statuses_count>  
  36.     <notifications></notifications>  
  37.     <verified>false</verified>  
  38.     <following></following>  
  39.   </user>  
  40. </status>  
  41. </statuses>  


其他可选参数 :

since_id : 返回从某Id开始的数据

page : user_timeline 调用会返回最近的 20 个 tweet,你可以用page来控制页数

count : 指定返回的记录数

# ------------------------

我的思路就是 在服务器 用一个php文件通过以上方法去取得这些数据,然后经过处理之后显示给浏览者

具体的实现代码放和使用方法在附件了!

效果 : http://blog.hzw513.com

附件: twitter.zip (1.37 K, 下载次数:51)

Tags: twitter, 翻墙

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):