An easy-to-use Python library for accessing the Sina Weibo API.
-
pip Install (bash):
pip3 install git+https://github.com/SYAN83/weibopy
-
Local install (bash):
Clone the repository to your local machine and in the repo's top level execute command:
python3 setup.py install
Sina Weibo API uses OAuth2 authorization framework.
To authorize, run the following lines in your python scripts:
import weibopy as wb
client_id = r'**********'
client_secret = r'********************************'
redirect_uri = 'https://***************'
oauth = wb.OAuthHandler(client_id, client_secret, redirect_uri).authorize()
Then follow the authorization instruction:
- load the authorization URL to the browser
- from the browser, authorize weibo API access (your username/password is required).
- when the page is redirected to the redirect URL, cope the entire URL and paste it to the input box to finish authorization.
WeiboPy follows (almost) the same structure as the Official Weibo API GET requests.
Example: return the user’s 2 latest timeline (http://open.weibo.com/wiki/2/statuses/user_timeline)
api = wb.API(oauth)
data, status = api.statuses.user_timeline(count=2)
# status == 200 for successful GET requests
print(data)