The use of the Python interface used by the Sina Weibo API

Source: Internet
Author: User

Sina Weibo's API provides a multilingual interface in which Python's interface is provided by the user @ Liu Xuefeng.

Download address and Description: http://michaelliao.github.com/sinaweibopy/

Description Document: Https://github.com/michaelliao/sinaweibopy/wiki/OAuth2-HOWTO

You can also see here: http://code.google.com/p/sinaweibopy/wiki/OAuth2

The code is great, but there's a little bit of it that might make me wait for the rookie to understand:

Code = your.web.framework.request.get (' code ')
This your.web.framework does not give an example of the framework. Therefore, we are small white worry, fortunately we have search engines, search the relevant solutions, but the explanation is not very detailed.

See Web site: http://blog.csdn.net/johnpher/article/details/7596525

And then I saw this, and it seemed to explain what I said,

See Web site: http://www.cnblogs.com/qianlifeng/archive/2012/02/12/2348366.html

My program code is as follows:

#!/usr/bin/env python #-*-coding:utf-8-*-from Weibo import apiclient import Webbrowser#python built-in packages App_key = ' Your KEY ' App_secret = ' your key ' Callback_url = ' callback address ' #利用官方微博SDK client = apiclient (App_key=app_key, App_secret=app_secret, redirect _uri=callback_url) #得到授权页面的url, use WebBrowser to open this URL url = client.get_authorize_url () print URL webbrowser.open_new (url  #获取code = later content print ' Enter the content behind the code in the URL and press ENTER: ' Code = raw_input () #code = your.web.framework.request.get (' code ') #client =
Apiclient (App_key=app_key, App_secret=app_secret, redirect_uri=callback_url) r = Client.request_access_token (code) Access_token = r.access_token # Sina returns token, similar to abc123xyz456 expires_in = r.expires_in # settings Get Access_token client.set_ Access_token (Access_token, expires_in) #可以打印下看看里面都有什么东西 #print client.statuses__public_timeline () statuses = Client.statuses__public_timeline () [' statuses '] length = len (statuses) #输出了部分信息 for I in Range (0,length): Print U ' nickname: ' +st atuses[i][' user ' [' screen_name '] print u ' profile: ' +statuses[i][' user ' [' description '] print u ' position: ' +statuses[i][' user '] [' Location '] print U ' Weibo: ' +statuses[i][' text '] 



The question about the callback address can be seen here: http://blog.csdn.net/monsion/article/details/8104257

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.