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.