Skip to content

Commit 8d10a89

Browse files
committed
添加微博情感分析的源代码
1 parent fa213f8 commit 8d10a89

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

源代码/WeiboAnalyse.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from weibopy import WeiboOauth2, WeiboClient
2+
import webbrowser
3+
4+
client_key = '262607354' # 你的 app key
5+
client_secret = '5345921237fa4ebe8d555a471f5a8da1' # 你的 app secret
6+
redirect_url = 'https://api.weibo.com/oauth2/default.html'
7+
8+
auth = WeiboOauth2(client_key, client_secret, redirect_url)
9+
# 获取认证 code
10+
webbrowser.open_new(auth.authorize_url)
11+
12+
# 在打开的浏览器中完成操作
13+
# 最终会跳转到一个显示 「微博 OAuth2.0」字样的页面
14+
# 从这个页面的 URL 中复制 code= 后的字符串
15+
# URL 类似这样 https://api.weibo.com/oauth2/default.html?code=9c88ff5051d273522700a6b0261f21e6
16+
17+
code = input('输入 code:')
18+
19+
# 使用 code 获取 token
20+
token = auth.auth_access(code)
21+
22+
print(token)
23+
24+
# token 是刚刚获得的 token,可以一直使用
25+
client = WeiboClient(token['access_token'])
26+
27+
# suffix 指定 API 的名称,parmas 是参数,在文档中有详细描述
28+
result = client.get(suffix='comments/show.json',
29+
params={'id': 4416407817336332, 'count': 200, 'page': 10})
30+
31+
print(result)

0 commit comments

Comments
 (0)