Application _python of micro-blog based on Python

Source: Internet
Author: User
Tags auth

This article illustrates the application of micro-blog based on Python, and share it for everyone's reference. Specifically as follows:

Before writing your own microblog application, you must first apply the public key and private key to the Weibo open platform application.
Download the Python version of the SDK, open the example directory, and encode it in the oauthsettokenupdate.py.

Copy Code code as follows:
#-*-Coding:utf-8-*-

From Weibopy.auth import Oauthhandler
From WEIBOPY.API Import API


consumer_key= ' applied key '
Consumer_secret = ' Application of App secret '

Auth = Oauthhandler (Consumer_key, Consumer_secret)
Auth_url = Auth.get_authorization_url ()
print ' Please authorize: ' + Auth_url
verifier = Raw_input (' PIN: '). Strip ()
Auth.get_access_token (verifier)
API = API (AUTH)

Status = Api.update_status (status= ' Hello World ', lat= ' 12.3 ', long= ' 45.6 ') # Note that the status must be a UTF-8 encoded string, which can be not written by latitude
Print Status.id
Print Status.text

Running this program will prompt a URL link, open the link in the browser, and give access, you will get a string of pin code. If you lose this pin, you will send a push, and the user's access token key and access token secret will also be displayed. You can see that the whole process is simple:

Create a Oauthhandler object auth with your Consumer_key and Consumer_secret.
Tell the user to visit Auth.get_authorization_url () and let the user authorize the application.
Get the user's pin and use Auth.get_access_token () to get the user's access token key and access token secret.
Create an API Object API with Auth.
The method that invokes the API, such as Update_status (), is the push. Detailed instructions can look at the API documentation.

Of course, it's silly to ask the user to enter a pin every time, so after using Auth.get_access_token () to get access token key and access token secret, you can use them to create the API objects directly:

Copy Code code as follows:
#-*-Coding:utf-8-*-

From Weibopy.auth import Oauthhandler
From WEIBOPY.API Import API


consumer_key= ' applied key '
Consumer_secret = ' Application of App secret '
token = ' User's access token key '
Tokensecret = ' User's access token secret '

Auth = Oauthhandler (Consumer_key, Consumer_secret)
Auth.settoken (token, Tokensecret)
API = API (AUTH)

Status = Api.update_status (status= ' wrap up ~ ')

I hope this article will help you with your Python programming.

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.