Skip to main content

cURL + Python Weibo Wrapper

Project description

rpweibo
=======

cURL + Python Weibo Wrapper.


## Installing

```bash
sudo python3 setup.py install
```

## Usage

### Initialize

```python
import rpweibo

example_app = rpweibo.Application(APP_KEY, APP_SECRET, REDIRECT_URI)
weibo = rpweibo.Weibo(example_app)
```

### Authorize

#### with Username and Password

```python
authenticator = rpweibo.UserPassAutheticator(USERNAME, PASSWORD)
try:
weibo.auth(authenticator)
except rpweibo.AuthorizeFailed:
print("Invalid username or password!")
```

#### with Existing Access Token

```python
authenticator = rpweibo.AccessTokenAuthenticator(ACCESS_TOKEN)
weibo.auth(authenticator)
```

### Using API

#### Styles

##### Procedural Style

```python
tweets = weibo.get("statuses/user_timeline")["statuses"]
for tweet in tweets:
print(tweet["text"])

weibo.post("statuses/update", status="Hello, world!")
```

##### Object Style

```python
tweets = weibo.api("statuses/user_timeline").get().statuses
for tweet in tweets:
print(tweet.text)

weibo.api("statuses/update").post(status="Hello, world!")
```

### Error Handling

```python
try:
tweets = weibo.api("statuses/user_timeline").get().statuses
except rpweibo.RemoteError:
# handle API errors likely cause by remote server
print("Something wrong with the server")
except rpweibo.CallerError:
# handle API errors likely cause by the client
print("You shouldn't use the API in this way")
except rpweibo.ResultCorrupted:
print("Request the API successfully, but got the corrupted result")
except rpweibo.NetworkError:
print("Somethings wrong with your network")
except rpweibo.APIError as e:
# Handle all API errors, including RemoteError and CallerError.
# NOTE: we handle both two type of API errors already, never reach here
print("%d - %s" % (e.error_code, e.error_message))
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpweibo-0.2.2.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file rpweibo-0.2.2.tar.gz.

File metadata

  • Download URL: rpweibo-0.2.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rpweibo-0.2.2.tar.gz
Algorithm Hash digest
SHA256 71efc915cdc8a0c28a8cea548987edba0dcb1be4a6dd8f0e115469105ad672cd
MD5 84821d224e2ea4423acc2e37bcdd5888
BLAKE2b-256 b2eaf24d3d115c7ff009080a10d6df28e8ee7844362369de818999c986d19854

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page