同步腾讯微博到WordPress[附 缓存版]

效果图:

本文提供,PHP / Javascript 两种调用的实例:

腾讯微博同步到wordpress

实现原理:

调用 腾讯微博API Beta[民间版] ,使用php解析,在wordpress中输出。

操作步骤:  [缓存版]  强烈推荐!神速

1、选好要插入,腾讯微博消息的地点,如:首页index.php,侧边栏sidebar.php,开始添加;

2、在Wordpress 根目录,新建文件夹名:txwb ,赋予权限 755 ,!!!否则无法写入文件缓存;

3、添加以下代码:

<?php
$id = 'XXX';//腾讯微博ID
$url = 'http://Q.zlz.im/'.$id;//腾讯微博API
$e = ABSPATH . 'wp-cache/'.$id.'.json';//缓存目录,需要777权限
$t = 3600; //设定再缓存间隔3600秒
if ( !is_file($e) || (time() - filemtime($e)) > $t ){//当缓存不存在或文件超过3600秒才更新
copy($url, $e);//拷贝到本地,一般主机都支持这个函数
}
$jsonObject = @file_get_contents($e);
$decodedArray = json_decode($jsonObject, true);
for($i = 0;$i < 5;$i++){ //数字5为调用的条数
echo '<li class="txmb"><span class="words left">'
.$decodedArray[data][info][$i][origtext].
'</span><span class="note right"> '
.$decodedArray[data][info][$i][timestamp].
'From'
.$decodedArray[data][info][$i][from].
'</span></li>';
}
?>

4、收工,关于美化样式,自己调整CSS吧。

—————看好了,我是分割线—————

非缓存版  [一般推荐] 速度一般

基本步骤同上,无需 第 2 步。
代码如下:

<?php
$id = 'XXX';//你的腾讯微博ID
$jsonObject = @file_get_contents('http://Q.zlz.im/'.$id); //调用腾讯微博API
$decodedArray = json_decode($jsonObject, true);
echo '<span>某某说'.$decodedArray[data][info][$i][origtext].'  发表于 ['.$decodedArray[data][info][$i][timestamp].'] 来自 ['.$decodedArray[data][info][$i][from].']</span>';
?>

任何问题,欢迎反馈@hzlzh_com

PS:最上面那幅图中另一条是Twi-t-ter信息,调用方法见:网站调取Twi-t-ter信息|格式化输出时间

————–看好了,我是更新分割线————–

Javascript 调用范例   [请注意API地址有变] http://q.zlz.im/js/+你的ID

DEMO地址:http://q.zlz.im/js/demo.html

<script type='text/javascript' src='http://q.zlz.im/js/hzlzh_com'></script>
<script type="text/javascript">
    document.write('<span>['+unescape(json.name)+']说:'+unescape(json.list[0].content)+'  发表于 ['+unescape(json.list[0].time)+'] 来自 ['+unescape(json.list[0].from)+']</span>');
</script>
版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《同步腾讯微博到WordPress[附 缓存版]

相关文章

{ Leave a Reply ? }

  1. 石头 China Internet Explorer Windows

    沙发~

  2. 阿邙 China Google Chrome Windows

    一会折腾出来玩玩 :mrgreen:

      • 阿邙 China Google Chrome Windows

        @HzlzH, 以前用过别人的 .. 再试试你的 :wink:

          • 阿邙 China Google Chrome Windows

            @HzlzH, 之前看过有个童鞋做了个插件的 你啥时候出插件啊?

              • 阿邙 China Google Chrome Windows

                @HzlzH, 干他Y的 嘿嘿。。
                玩笑啦, 还是小心为妙。。

  3. 羽中 China Mozilla Firefox Windows

    API是你自己调用的?

  4. Ray Chow China Google Chrome Windows

    那怎么什么内容都没有

      • Ray Chow China Google Chrome Windows

        @HzlzH, 我是说你的首页刚刚疼讯微博没内容……不过现在有了

  5. 万戈 China Mozilla Firefox Windows

    你玩的越来越精通了哈~

  6. 奥德雷的雷人事迹 China Mozilla Firefox Windows

    我就不这么复杂了 :roll:

  7. Neeke China Mozilla Firefox Windows

    :mrgreen: 刚刚睡觉的时候迷迷糊糊想到给加个缓存,我每次打开首页都去请求TX,太频繁了估计有危险,赶紧起床上来准备改代码,过来看看看到你也加了,O(∩_∩)O哈哈~

      • Neeke China Internet Explorer Windows

        @HzlzH, :-D 还好我那就我一个人用

      • Neeke China Internet Explorer Windows

        @HzlzH,
        $t = 360; //设定再缓存间隔360秒,也就是1小时, 单位:秒
        这个你是不是算错啦?360秒=1小时?

          • Neeke China Internet Explorer Windows

            @HzlzH, :mrgreen: 再盖一层。

  8. 本站拥有网赚教程 其他各种教程 美食健康

    个人博客招友情链接
    只要在首页加入本站链接,本站就会在首页显示您的链接!

  9. 呵呵 China Internet Explorer Windows

    :twisted: 全是英文。头痛啊

  10. Neeke China Mozilla Firefox Windows

    :-D 我刚刚抓包发现不需要密码,不需要登录,只需要任何一个人的ID就能读出他的数据来。

      • Neeke China Internet Explorer Windows

        @HzlzH, :mrgreen: 暂时都保留吧,全被封了就真悲剧了。

          • Neeke China Internet Explorer Windows

            @HzlzH, 是啊是啊,TX是啥RP大家都知道。

  11. 哲哲 China Mozilla Firefox Windows

    又见一个技术型博客·呵呵·新浪微博玩好久了·twitte也是最近才玩的多一些·腾讯的不打算玩了·虽然很看好

  12. houkai China Internet Explorer Windows

    越来越方便了 牛呀 自己搞了这么多


  13. Warning: printf() [function.printf]: Too few arguments in /home/zlz/domains/zlz.im/public_html/wp-content/themes/dot-b/functions.php on line 172

    这个似曾相识哦
    你的也加escape了

  14. 淡水七度 China Google Chrome Windows

    :wink: 还是等腾讯的API吧 但愿不要太久

  15. winy China Mozilla Firefox Windows

    我不用这么多,就调用嘀咕的api就好了,其它的全部同步到嘀咕

  16. 海天无影 China Mozilla Firefox Windows

    哇 强大啊~
    我现在在考虑 是不是坏掉twitter~

  17. 再现9527 China Google Chrome Windows

    :roll: 呵呵,用新浪微博吧,有挂件

  18. heson China Google Chrome Windows

    不错啊 twitter注册不来

  19. 阿邙 China Google Chrome Windows

    为何我使用js版出来不是和你的那样 第一个字是乱码呢

  20. 超人 China Mozilla Firefox Windows

    太爽了。。腾讯围脖也可以同步。以后不翻墙了

  21. 闲云野鹤 China Google Chrome Windows

    好像有问题,我刚开始同步了,后来就不显示了,必须删除了缓存才可以.难道我更新的频率有问题?我是默认的3600s更新一次呀!

  22. 朵未 China Maxthon Windows

    终于搞定了,哈哈。多谢你的api

  23. abcx China Google Chrome Windows

    是不是现在不行了呀?

  24. 小陆 China Internet Explorer Windows

    我的搞定了,其实很简单

  25. 空空裤兜 China Google Chrome Windows

    API总会不稳定,教一下在自己的服务器搭建API,不会把方法外传了的

  26. 长岛冰泪 China Mozilla Firefox Windows

    自力同学喜欢绕弯
    ajax+jsonp就ok了嘛

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)

Pingback & Trackback

  1. Tweets that mention 同步腾讯微博到Wordpress[附 缓存版] | 自力博客 -- Topsy.com United States Unknow Browser Unknow Os - Pingback on 2010/06/26/ 19:51
  2. Api获取多条腾讯微博信息并缓存 |阿邙'S Blog United States WordPress Unknow Os - Pingback on 2010/07/21/ 06:42
  3. 同步腾讯微博到WordPress | Note:ongakuer United States WordPress Unknow Os - Pingback on 2010/10/07/ 08:42
  4. 给自己的Wordpress博客添加腾讯微博客 | 七叶草博客 United States WordPress Unknow Os - Pingback on 2010/11/26/ 21:43