Python: Send Sina Weibo via command line

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.