Odnoklassniki REST API wrapper.
Project description
This library consists of an API interface for Odnoklassniki and Django middleware which helps to configure it.
Usage example:
import pyodnoklassniki
pyodnoklassniki.app_pub_key = 'CBAJ...BABA'
pyodnoklassniki.app_secret_key = '123...XYZ'
ok_api = pyodnoklassniki.OdnoklassnikiAPI(
access_token='kjdhfldjfhgldsjhfglkdjfg9ds8fg0sdf8gsd8fg')
try:
print ok_api.users.getCurrentUser()
except pyodnoklassniki.OdnoklassnikiError as exc:
print exc
You might find that configuring library with Django Middleware is more convenient.
MIDDLEWARE_CLASSES = (
# ...
'pyodnoklassniki.contrib.django.middleware.PyOdnoklassnikiMiddleware',
# ...
)
PYODNOKLASSNIKI = {
'app_pub_key': 'CBAJ...BABA',
'app_secret_key': '123...XYZ',
}
Use dotted notation to invoke API method. Query parameters are passed as keyword arguments. Odnoklassniki error codes are grouped by meaning in exceptions.py, but OdnoklassnikiError might be enough. See full list of API methods and error codes at Odnoklassniki API documentation.
try:
response = ok_api.group.getUserGroupsV2()
except pyodnoklassniki.OdnoklassnikiError as exc:
print exc
else:
for group in response['groups']:
print ok_api.group.getInfo(uids=group['groupId'],
fields='name, description')
You can process particular error code such as PARAM_SESSION_EXPIRED as well.
from pyodnoklassniki import errors
try:
response = ok_api.users.getCurrentUser()
except pyodnoklassniki.AuthError as exc:
if exc.code == errors.PARAM_SESSION_EXPIRED:
# Renew session...
pass
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
File details
Details for the file pyodnoklassniki-0.2.tar.gz
.
File metadata
- Download URL: pyodnoklassniki-0.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa1222e8f07737d0e00af09feeb6582c97f3eb25673eee9c72e63f69a43c0449 |
|
MD5 | e9ea338b19f7fef6ad1e2c9e950b3d2d |
|
BLAKE2b-256 | 526d73eb813d121a1c3af4270c623dc4a42d53069413741dbd791d45f36e6759 |