1, register a SINA application, get Appkey and secret, as well as token, write this information to the configuration file Sina_weibo_config.ini, the contents are as follows, just for example:
Copy Code code as follows:
[UserInfo]
consumer_key=8888888888
consumer_secret=777777f3feab026050df37d711200000
token=2a21b19910af7a4b1962ad6ef9999999
token_secret=47e2fdb0b0ac983241b0caaf45555555
2, call Sina Weibo's open Api, code:
Copy Code code as follows:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
From Weibopy.auth import Oauthhandler
From WEIBOPY.API Import API
Import Configparser
Def Press_sina_weibo ():
"
calling Sina Weibo open API implementation to write blog posts through the command line, features need to be improved
author:socrates
date:2012-02-06
Sina Weibo: @ Sheep without ears
'
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 edition)
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 ()
3, the Operation effect:
Command Line Input:
4, micro-Bo sent successful results: