Skip to main content

OldVKAPI

Синхронный Python-клиент к API из OldVK.apk v1.3.1 (com.vkontakte.android). Протокол восстановлен дизассемблированием classes.dex — подробности в OldVK_API.md (главы 2–10).

Коротко о протоколе: все вызовы — POST http(s)://oldvk.mooo.com:8080/api.php с полями method/v=3.0/format=json/api_id=2274003 + параметры + sig (MD5(uid + сортированные key=value + secret)) + sid. Авторизация — auth.getTokenSecuredigest(MD5)auth.getSessionSecure.

Установка

pip install requests
pip install -e .   # из каталога OldVKAPI

Быстрый старт

from oldvkapi import OldVK

vk = OldVK(session_file="~/.oldvkapi/session.json",
           auto_reauth=True,      # молча обновлять сессию при error 3/4
           network_retries=2)     # повторять при обрывах сети

# Вход логином (один раз; дальше сессия берётся из JSON-файла):
vk.login("user@example.com", "password")

# или готовой сессией:
# vk = OldVK.from_session(uid=123, sid="...", secret="...")

print(vk.messages.dialogs())          # диалоги через execute-шаблон
print(vk.wall.posts(owner_id=123))    # посты стены
vk.activity.online()                  # heartbeat онлайна

Разделы

Доступ — свойствами клиента, методы повторяют имена API из APK:

Свойство Методы (примеры)
users get_profiles(uids, fields, name_case)
friends get, get_by_phones, add, delete, mutual, get_requests
groups get_by_id
status get, set
activity online
messages send, get_history, get_by_id, delete, mark_as_read, dialogs, search, slow_poll*
wall post, delete, add_comment, delete_comment, get_comments, add_like, delete_like, posts*
likes add, delete
polls add_vote, get_by_id
photos get_albums, get, get_user_photos, get_by_id, get_comments, get_tags, create_comment, create_album, edit_album, delete_album, delete, edit, comments_full, info
video get, save, get_comments
audio get, get_albums, search, add, delete, direct_url*
docs get_upload_server, save
notes get_by_id, get_comments
places search, get_checkins, checkin, add, get_by_id, get_city_by_id, get_country_by_id
newsfeed get, get_comments

* — через execute (готовые шаблоны в oldvkapi/execute.py).

Прямой вызов любого метода: vk.call("wall.post", owner_id=1, message="hi").

Ошибки и капча

from oldvkapi import CaptchaNeeded, ReauthNeeded, ApiError

try:
    vk.wall.post(owner_id=1, message="hi")
except CaptchaNeeded as cap:
    print(cap.captcha_img)          # показать картинку пользователю
    key = input("Капча: ")
    vk.call(cap.method, captcha_sid=cap.captcha_sid,
            captcha_key=key, **cap.params)
except ReauthNeeded:
    vk.reauth()                     # нужен login() с паролем в памяти
except ApiError as err:
    print(err.code, err.message)

Автоматический режим — без try/except (повтор делает сам клиент):

vk = OldVK(session_file="session.json",
           captcha_handler=lambda img, sid, method, params: input(f"{img}: "))
vk.wall.post(owner_id=1, message="hi")   # re-auth и капча — автоматически

error_code 7 возвращается как None (как в самом приложении).

LongPoll

for update in vk.longpoll.updates():   # бесконечный генератор
    print(update)

refresh() — новый server/key/ts; poll_url() — текущий a_check-URL; slow_poll(time_offset) — запасной опрос из приложения.

Загрузка файлов

vk.uploader.upload_wall_photo("pic.jpg", owner_id=vk.uid, message="Фото!")
vk.uploader.upload_album_photo(aid=123, file_path="pic.jpg")
vk.uploader.upload_audio("track.mp3")
vk.uploader.upload_doc("file.pdf")
vk.uploader.upload_video("Ролик", "vid.mp4", description="...")

Оговорка про digest

Формула digest = MD5(SECRET:nonce:login:password) восстановлена из байт-кода Auth.doAuth (порядок операндов — по append-цепочке). Если сервер её отвергнет — используйте oldvkapi.auth.auth_session_raw(nonce, login, digest) с собственной формулой.

Download files

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

Source Distribution

oldvkapi-0.2.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oldvkapi-0.2.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file oldvkapi-0.2.0.tar.gz.

File metadata

  • Download URL: oldvkapi-0.2.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for oldvkapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 32be1d99bfb1d34b1fe576ef70ce994150c07a90fa0a208cc4763ace50aa5324
MD5 5ef63b90a4a198af31d935c1fdbaf318
BLAKE2b-256 04ea0674b7fa69d744de950e5622faa28802a69a5770323479b93aa812f75eb2

See more details on using hashes here.

File details

Details for the file oldvkapi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: oldvkapi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for oldvkapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d01b64a364e20e7ea2bc24b85c997e691d4428086ac6f044226f2b7958c0b496
MD5 5befd40783798847a7b0a61b93a6a639
BLAKE2b-256 be5adf1505225b94590e5121dd34421e5fc4bdad9324a6fe2fd499d331be9d03

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page