1. Register a Sina application, get the appkey, secret, and Token, and write the information to the configuration file sina_weibo_config.ini. The content is as follows, for example only:
[Userinfo] consumer_key = 88888888consumer_secret = 777777f3feab026050df37d711200000token = token = 47e2fdb0b0ac983241b0caaf455555
2. Call the Open API of Sina Weibo, code:
#! /Usr/bin/ENV Python #-*-coding: UTF-8-*-from weibopy. auth import oauthhandlerfrom weibopy. API import apiimport configparserdef press_sina_weibo (): ''' call Sina Weibo open API to write a blog via command line. The function needs to be improved: Author: Socrates Date: Sina Weibo: @ yourobject'' sina_weibo_config = configparser. configparser () # Read the appkey configuration file try: sina_weibo_config.readfp (open ('sina _ weibo_config.ini ') cannot configparser. error: Print 'read sina_weibo_config.ini failed. '# obtain required information consumer_key = sina_weibo_config.get ("userinfo", "consumer_key") consumer_secret = sums ("userinfo", "consumer_secret") token = sums ("userinfo ", "token") token_sercet = sina_weibo_config.get ("userinfo", "token_secret") # Call Sina Weibo openapi (Python version) auth = oauthhandler (consumer_key, consumer_secret) Auth. settoken (token, token_sercet) API = API (auth) # Enter weibo_content = raw_input ('Please input content: ') status = API through the command line. update_status (status = weibo_content) print "Press Sina Weibo successful, content is: % s" % status. text if _ name _ = '_ main _': press_sina_weibo ()
3. effect:
Command Line input:
4. Weibo content: