zoukankan      html  css  js  c++  java
  • 搜索引擎--范例:新浪微博API获取最近的微博--statuses/public_timeline

    新浪微博平台跟新浪SAE一样,都是一个字“坑”,好了,不再吐槽,直入主题

    1:直接登录新浪,添加网站,就直接添加我们在新浪SAE上创建的应用即可

    2:填写信息,ICP备案信息号填写sinaapp.com的备案号就行了,图标的话用photoshop应该问题不大

    3:获取key和serect,我们这种小打小闹的网页一般很难通过审核的,但是没关系,只要我们能获得测试账号就行了

         只要审核了,不管通不通过,就可以用测试账号的key和serect了,所以,尽管提交审核就好了

    4:代码如下,是参考网上的,不过现在找不到那个博客啦,。。。。。,所以没外链。。。

    import sys
    #在微博开放平台上的SDK中找到python SDK,下载安装就行
    import weibo import webbrowser import json
    #舔你的微博开放平台网站的key APP_KEY
    = '643524640'
    #对应的serect
    MY_APP_SECRET = '32f7d34f4d826b818a05be54c161c933'
    #这个可以对应SAE应用的url REDIRECT_URL = 'http://irsearch.sinaapp.com/' #要想看懂这些代码,努力的去看python SDK吧 api = weibo.APIClient(APP_KEY, MY_APP_SECRET) authorize_url = api.get_authorize_url(REDIRECT_URL) #print(authorize_url) webbrowser.open_new(authorize_url) code = raw_input() request = api.request_access_token(code, REDIRECT_URL) access_token = request.access_token expires_in = request.expires_in api.set_access_token(access_token, expires_in) #public_timeline有三个参数

    t = api.statuses__public_timeline(count=1)

    5:返回的数据格式是weibo.JsonDict,并且其中的中文使用unicode编码

         可以用python的json进行转化

      

    #接上面
    print
    (t) print(type(t)) te = json.dumps(t,ensure_ascii=False) print(type(te)) print(te) tem = json.loads(te) print(type(tem)) print(tem)

    结果部分如下:

    {"interval": 0, "hasvisible": false, "total_number": 1, "previous_cursor": 0, "next_cursor": 0, "statuses": [{"reposts_count": 0, "truncated": false, "text": ""激情世界杯  满减送不停",这个活动推荐给大家。 地址:http://t.cn/RvuECDN", "visible": {"type": 0, "list_id": 0}, "in_reply_to_status_id": "", "bmiddle_pic": "http://ww1.sinaimg.cn/bmiddle/df70fb22gw1ehy9a62v03j209v0afwh9.jpg", "id": 3728023935535065, "thumbnail_pic": "http://ww1.sinaimg.cn/thumbnail/df70fb22gw1ehy9a62v03j209v0afwh9.jpg", "mid": "3728023935535065", "source": "<a href="http://app.weibo.com/t/feed/59hmLP" rel="nofollow">微活动</a>", "attitudes_count": 0, "in_reply_to_screen_name": "", "pic_urls": [{"thumbnail_pic": "http://ww1.sinaimg.cn/thumbnail/df70fb22gw1ehy9a62v03j209v0afwh9.jpg"}], "annotations": [{"source": {"url": "http://event.weibo.com/23382470", "title": "激情世界杯  满减...", "id": "23382470", "name": "激情世界杯  满减送不停", "appid": "38"}}], "in_reply_to_user_id": "", "darwin_tags": [], "favorited": false, "original_pic": "http://ww1.sinaimg.cn/large/df70fb22gw1ehy9a62v03j209v0afwh9.jpg", "idstr": "3728023935535065", "user": {"bi_followers_count": 9, "domain": "", "avatar_large": "http://tp2.sinaimg.cn/1801120077/180/5683836874/1", "verified_source": "", "ptype": 0, "statuses_count": 312, "allow_all_comment": true, "id": 1801120077, "verified_reason_url": "", "city": "1", "province": "44", "block_app": 0, "follow_me": false, "verified_reason": "", "followers_count": 186, "location": "广东 广州", "verified_trade": "", "mbtype": 0, "verified_source_url": "", "profile_url": "u/1801120077", "block_word": 0, "avatar_hd": "http://ww1.sinaimg.cn/crop.0.0.200.200.1024/6b5ae94djw1ec877cl1trj205k05kmx9.jpg", "star": 0, "description": "", "friends_count": 371, "online_status": 1, "mbrank": 0, "allow_all_act_msg": true, "profile_image_url": "http://tp2.sinaimg.cn/1801120077/50/5683836874/1", "idstr": "1801120077", "verified": false, "geo_enabled": true, "class": 1, "screen_name": "车赣刺", "lang": "zh-cn", "weihao": "", "remark": "", "favourites_count": 0, "name": "车赣刺", "url": "", "gender": "m", "created_at": "Mon Aug 23 18:32:22 +0800 2010", "worldcup_guess": 0, "verified_type": -1, "following": false}, "geo": null, "created_at": "Wed Jul 02 23:07:12 +0800 2014", "mlevel": 0, "comments_count": 0}]}

    6:这是一个字典,大家想怎么用就怎么用吧

  • 相关阅读:
    在ASP.NET开始执行HTTP请求的处理程序之前
    要在一般处理程序中获取其他页面的session值
    asp.net中session的原理及应用
    INTRAWEB说明书
    ASP.NET万能JSON解析器
    使用 IntraWeb (30)
    IntraWeb例子练习
    【整理】Asp.net HttpWebRequest和HttpWebResponse发送和接受任何类型数据
    Delphi 接口机制真相
    http://www.doc88.com/p-203939126010.html
  • 原文地址:https://www.cnblogs.com/qwj-sysu/p/3821359.html
Copyright © 2011-2022 走看看