网站调用新浪微博内容(新浪SAE吐槽:字“坑”,好了!)
优采云 发布时间: 2022-01-05 02:12网站调用新浪微博内容(新浪SAE吐槽:字“坑”,好了!)
新浪微博平台与新浪SAE相同,同一个“坑”字
1:直接登录新浪,添加网站,然后直接添加我们在新浪SAE上创建的应用
2:填写信息,只需填写ICP备案信息号的备案号即可。如果使用图标,photoshop应该没有问题
3:拿到钥匙并安装。小样的网页我们一般很难通过审核,不过没关系,只要能拿到测试账号就可以了。
只要审核通过,无论通过与否,测试账号的key和secret都可以使用,提交审核即可。
4:代码如下,参考网上,但是现在找不到那个博客了。. . . . ,所以没有外链。. .
import sys<br />#在微博开放平台上的SDK中找到python SDK,下载安装就行
import weibo
import webbrowser
import json <br />#舔你的微博开放平台网站的key
APP_KEY = '643524640'<br />#对应的serect
MY_APP_SECRET = '32f7d34f4d826b818a05be54c161c933'<br />#这个可以对应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有三个参数
<br />t = api.statuses__public_timeline(count=1)
5:返回的数据格式为weibo.JsonDict,其中中文采用unicode编码
可以使用python的json进行转换
#接上面<br />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:这是一本字典,你想怎么用就怎么用