https://github.com/marselester/pyodnoklassniki
Odnoklassniki REST API wrapper.
https://github.com/marselester/pyodnoklassniki
Last synced: about 1 month ago
JSON representation
Odnoklassniki REST API wrapper.
- Host: GitHub
- URL: https://github.com/marselester/pyodnoklassniki
- Owner: marselester
- License: mit
- Created: 2013-09-04T16:16:30.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-07-21T04:14:13.000Z (almost 8 years ago)
- Last Synced: 2024-05-02T00:42:35.669Z (about 1 year ago)
- Language: Python
- Size: 27.3 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=================================================
PyOdnoklassniki is Odnoklassniki REST API wrapper
=================================================.. image:: https://travis-ci.org/marselester/pyodnoklassniki.png
:target: https://travis-ci.org/marselester/pyodnoklassnikiThis library consists of an API interface for `Odnoklassniki`_ and
Django middleware which helps to configure it.Usage example:
.. code-block:: python
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 excYou might find that configuring library with Django Middleware is more
convenient... code-block:: python
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`_... code-block:: python
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.
.. code-block:: python
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.. _Odnoklassniki: http://odnoklassniki.ru
.. _Odnoklassniki API documentation: http://apiok.ru/wiki/display/ok/Odnoklassniki+REST+API+ru