Skip to main content

ok.ru Python REST API wrapper

Project description

ok.ru Python REST API wrapper

About

This is ok.ru (Russian social network) python API wrapper. The goal is to support all API methods: https://apiok.ru/en/dev/methods/rest.

Getting Started

Install package using pip

pip install aiookru

To use OK API you need a registered app and account in the social network.

  1. Sign up in ok.ru
  2. Create external application.
  3. Save App ID, App key, App secret key.
  4. Use App ID, list of required permissions and user credentials to get access token.
  5. Use the access token to make method requests.

After signing up go to https://apiok.ru/en/dev/app/create and create application.

app_id = 'app ID'
app_key = 'app key'
app_secret_key = 'app secret'

ImplicitSession

You can authenticate with OK API OAuth by passing user credentials and permissions to ImplicitSession (or ImplicitClientSession/ ImplicitServerSession).

from aiookru.sessions import ImplicitSession

phone = '+1999123456'
password = 'user password'

session = await ImplicitSession(
    app_id=app_id,
    app_key=app_key,
    app_secret_key=app_secret_key,
    login=phone,
    passwd=password,
    permissions='VALUABLE_ACCESS',
)

Now you can execute API requests (see Executing API requests). After authentication you will get access token session.access_token and session secret key session.session_secret_key. Save them to make requests later:

access_token = session.access_token
session_secret_key = session.session_secret_key

TokenSession

If you already have either of two:

  • app_secret_key and access_token
  • session_secret_key
from aiookru.sessions import TokenSession

session = TokenSession(
    app_key=app_key,
    app_secret_key=app_secret_key,
    access_token=access_token,
    session_secret_key=session_secret_key,
)

you can instantiate TokenSession (or ClinentSession/ServerSession) and execute requests.

Executing API requests

from aiookru import API

api = API(session)

# current user's friends
friends = await api.friends.get()

Under the hood each API requests is encriched with:

  • application_key
  • sig
  • app_secret_key and access_token or session_secret_key
  • format
  • method

By default, the sessions try to infer which signature circuit to use:

  • if app_secret_key and access_token are not empty strings - server-server signature circuit is used
  • else if session_secret_key is not empty string - client-server signature circuit is used
  • else exception is raised

You can explicitly choose a circuit for signing requests by passing to API one of the following sessions:

Sever-Server circuit

from aiookru import ImplicitServerSession, API
session = await ImplicitServerSession(app_id, app_key, app_secret_key, phone, password)
api = API(session)

or if you already have an access token

from aiookru import ServerSession, API
session = ServerSession(app_key, app_secret_key, access_token)

Client-Server circuit

from aiookru import ImplicitClientSession, API
session = await ImplicitClientSession(app_id, app_key, phone, password)
api = API(session)

or if you already have a session secret key

from aiookru import ClientSession, API
session = await ClientSession(app_key, session_secret_key)
api = API(session)

License

aiookru is released under the BSD 2-Clause License.

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

aiookru-0.0.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

aiookru-0.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file aiookru-0.0.1.tar.gz.

File metadata

  • Download URL: aiookru-0.0.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for aiookru-0.0.1.tar.gz
Algorithm Hash digest
SHA256 62405cddc15cc7cc9cde51a991e392e84ff385527d085a3d355ac4445dcb53d0
MD5 8966deb867a7cf7af9c9671d1edcabb1
BLAKE2b-256 1cdecc5e0af25ea6fdff868127b876ed8e14f72e7c05cf308af113b1dd236c8d

See more details on using hashes here.

File details

Details for the file aiookru-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: aiookru-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for aiookru-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f170079b62530e946b65eb2edfcfc7e04ecf2dc7360fd55782b946d6e08370bb
MD5 78867fcbf0f4b71ffd00e4353fe820e5
BLAKE2b-256 207a2841c3cb2a5d39788e734394188d6bc308a8c48ef991f4f6e8490b7bca4a

See more details on using hashes here.

Supported by

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