Python SDK for Weibo API
Project description
PyWeibo
Python SDK for Weibo API.
Installation
pip install pyweibo
Preparation
-
Register the Sina Weibo account, and establish a new app in open.weibo.com.
-
Get
App Key
andApp Secret
from 应用信息 -> 基本信息 -
Set
Redirect URI
in 应用信息 -> 高级信息 -> OAuth2.0授权设置 as:
Usage
Authentication
Basic usage:
from pyweibo import Auth
auth = Auth()
When running, you need to manually input App Key
and App Token
:
App Key: <Your App Key>
App Secret: <Your App Secret>
Next the web browser will automatically open the redirect uri.
Copy the uri to the console and the token will be generated:
Input the url or the token: <The URL or token>
Finally the token will also be stored in ./token.json
.
As for advance usages, you can specify:
-
The way to read app key and secret from the local file:
LocalFileReader('./app.json')
-
The redirect uri, default is https://api.weibo.com/oauth2/default.html
API Client
Basic usage:
from pyweibo import Auth, Client
# Get the token
auth = Auth()
token = auth.token.token
# Start the client
client = Client()
data = client.statuses.home_timeline.get(access_token=token)
The APIs can be referred from Official Doc.
You can access the api via client.api_name_1.api_name_2.get(param1=value1, param2=value2)
, where the last method call must be get
or post
.
Also you can use dict index like client[api_name_1][api_name_2].get(param1=value1, param2=value2)
.
The return value is a TextDict
, where you can access the attributes directly like:
user = data.statuses[0].user
Also you can upload the picture like this:
with open('image.png', 'rb') as f:
client.statuses.upload.post(status='Image', pic=f)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyweibo-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99fe1686f63c9f9e3de681ad7ee19fb21cf3b1377e9efc68ef386633910d5459 |
|
MD5 | 99888fe4eb87e6c96471a40c35647a11 |
|
BLAKE2b-256 | 93e97ae6ecc552477d7d627f0191a7f1a21b2256bc9fb863d5489cf37773ffe4 |