ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1、申请个应用,得到App Key和App Secret 2、设置授权回调页地址,如下,如果不设置,打开回调页时会报错“error:redirect_uri_mismatch”,这一点一定要注意。 ![QQ截图20121204003722](https://box.kancloud.cn/2016-06-08_57579361db142.jpg) 3、代码: ~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- from weibo import * def press_sina_weibo(): APP_KEY = '220567XXXX' APP_SECRET = '47970abb02d8f7b4d600d98e9bXXXXXX' CALLBACK_URL = 'https://api.weibo2.com/oauth2/default.html' client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) print client.get_authorize_url() r = client.request_access_token(raw_input("input code:").strip()) client.set_access_token(r.access_token, r.expires_in) print client.post.statuses__update(status=u'测试一下发送微博') if __name__ == '__main__': press_sina_weibo() ~~~ 4、测试: 运行后,会输出一个URL,在地址栏中打开,得到token,然后输入后就可发送了。 ![QQ截图20121204004351](https://box.kancloud.cn/2016-06-08_57579362038e3.jpg) ![QQ截图20121204004234](https://box.kancloud.cn/2016-06-08_575793621ac0b.jpg) ![QQ截图20121204004455](https://box.kancloud.cn/2016-06-08_5757936230521.jpg) ![QQ截图20121204004351](https://box.kancloud.cn/2016-06-08_57579362038e3.jpg)