首页 > 代码库 > Python 获取新浪微博的最新公共微博

Python 获取新浪微博的最新公共微博

API:

statuses/public_timeline  返回最新的200条公共微博,返回结果非完全实时 

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-7-3
@author: guaguastd
@name: statuses_public_timeline.py
'''

def public_timeline(weibo_api, count):
    
    #public_timeline = weibo_api.statuses.public_timeline.get(count=count)
    public_timeline = weibo_api.statuses__public_timeline(count=count) 
    statuses = public_timeline['statuses']
    return statuses

if __name__ == '__main__':
    
    # import json
    import json
    
    # import login, see http://blog.csdn.net/guaguastd/article/details/33664443 
    from login import weibo_login

    # get the twitter access api
    weibo_api = weibo_login()
    
    # get the new 200 weibo
    content = public_timeline(weibo_api, 200)
    print json.dumps(content, indent=1)

RESULT:

['cc7c9d31fc797802960c84822c3654f3']
[
 {
  "reposts_count": 0, 
  "truncated": false, 
  "text": "\u5982\u679c\u4f60\u4e5f\u6709\u75d8\u75d8 \u75d8\u5370 \u6bdb\u5b54\u7c97\u5927 \u6697\u6c89\u6591\u70b9 \u5e72\u71e5 \u7ea2\u8840\u4e1d \u51fa\u6cb9\u9ed1\u5934 \u9ed1\u773c\u5708 \u773c\u888b \u62a4\u7406 \u51cf\u80a5 \u7b49\u7b49\u53ef\u4ee5\u52a0\u8001\u5e08QQ:1817712253\u4e00\u8d77\u5b66\u4e60", 
  "visible": {
   "type": 0, 
   "list_id": 0
  }, 
  "in_reply_to_status_id": "", 
  "bmiddle_pic": "http://ww3.sinaimg.cn/bmiddle/d1a02cb3jw1ehz8g6t1m6j20c90cdq3n.jpg", 
  "id": 3728143255299328, 
  "thumbnail_pic": "http://ww3.sinaimg.cn/thumbnail/d1a02cb3jw1ehz8g6t1m6j20c90cdq3n.jpg", 
  "mid": "3728143255299328", 
  "source": "<a href=http://www.mamicode.com/"http://app.weibo.com/t/feed/3auC5p/" rel=/"nofollow/">/u76ae/u76ae/u65f6/u5149/u673a", >