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.
- Sign up in ok.ru
- Create external application.
- Save App ID, App key, App secret key.
- Use App ID, list of required permissions and user credentials to get access token.
- 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
andaccess_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
andaccess_token
orsession_secret_key
format
method
By default, the sessions try to infer which signature circuit to use:
- if
app_secret_key
andaccess_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
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.