Weibo applications written in python and blog applications written in python

Source: Internet
Author: User

Weibo applications written in python and blog applications written in python

This article provides an example of a microblog application written based on python and shares it with you for your reference. The details are as follows:

Before writing your own weibo application, you must apply for the public key and private key of the application on the weibo open platform.
Download the python SDK, open the example directory, and encode it like oauthSetTokenUpdate. py,

Copy codeThe Code is as follows: #-*-coding: UTF-8 -*-

From weibopy. auth import OAuthHandler
From weibopy. api import API


Consumer_key = 'application key'
Consumer_secret = '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, latitude and longitude can be not written
Print status. id
Print status. text

When you run this program, a URL link is displayed. You can open this link in your browser and grant the access permission. Then, you will get a string of PIN codes. After this PIN code is entered, a push message is sent, and the user's Access token key and Access token secret are displayed. The whole process is very simple:

Use your consumer_key and consumer_secret to create an OAuthHandler object auth.
Instruct the user to access auth. get_authorization_url () and authorize the application.
Get the user's PIN code and use auth. get_access_token () to get the user's Access token key and Access token secret.
Use auth to create an API object api.
The method used to call the api. For example, update_status () is the push method. For more information, see the API documentation.

Of course, it is too silly to ask the user to enter the PIN code every time, So auth is used. after get_access_token () obtains the Access token key and Access token secret, you can directly use them to create API objects:

Copy codeThe Code is as follows: #-*-coding: UTF-8 -*-

From weibopy. auth import OAuthHandler
From weibopy. api import API


Consumer_key = 'application key'
Consumer_secret = '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 = 'get it done ~ ')

I hope this article will help you with Python programming.


How to Use python to write a Sina Weibo Program

See:

Www.oschina.net/code/snippet_9451110825971
 
Write python code: Collect all comments from any account on Sina Weibo. The account and password are unknown.

Using the sdk APIs, you can obtain the id of a Weibo user based on Weibo, and then obtain all the Weibo users based on the id, finally, retrieve the comment list of the Weibo according to the Weibo id.

Statuses/user_timeline/ids
Obtain the ID of the Weibo post.

Comments/show
Return the comment list of a microblog Based on the Weibo ID.

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.