100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > python发微博_Python使用新浪微博API发送微博的例子

python发微博_Python使用新浪微博API发送微博的例子

时间:2023-02-19 20:42:15

相关推荐

python发微博_Python使用新浪微博API发送微博的例子

#!/usr/bin/env python

# -*- coding: utf-8 -*-

from weibopy.auth import OAuthHandler

from weibopy.api import API

import ConfigParser

def press_sina_weibo():

'''

调用新浪微博Open Api实现通过命令行写博文,功能有待完善

author: socrates

date:-02-06

新浪微博:@没耳朵的羊

'''

sina_weibo_config = ConfigParser.ConfigParser()

#读取appkey相关配置文件

try:

sina_weibo_config.readfp(open('sina_weibo_config.ini'))

except ConfigParser.Error:

print 'read sina_weibo_config.ini failed.'

#获取需要的信息

consumer_key = sina_weibo_config.get("userinfo","CONSUMER_KEY")

consumer_secret =sina_weibo_config.get("userinfo","CONSUMER_SECRET")

token = sina_weibo_config.get("userinfo","TOKEN")

token_sercet = sina_weibo_config.get("userinfo","TOKEN_SECRET")

#调用新浪微博OpenApi(python版)

auth = OAuthHandler(consumer_key,consumer_secret)

auth.setToken(token,token_sercet)

api = API(auth)

#通过命令行输入要发布的内容

weibo_content = raw_input('Please input content:')

status = api.update_status(status=weibo_content)

print "Press sina weibo successful,content is: %s" % status.text

if __name__ == '__main__':

press_sina_weibo()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。