@zotov/vk-connector
v0.1.1
Published
Framework-agnostic connector for reading VK photo albums and videos client-side.
Downloads
295
Readme
@zotov/vk-connector
Client-side connector for reading a VK community's photo albums and videos
(photos.get / video.get). No framework or UI-library dependency —
plain functions and types, usable from any project (Vue, React, vanilla, ...).
Why
VK photo/video albums are a convenient free CMS for photo/video-heavy marketing sites. This package wraps the JSONP calls and typing so the same connector can be dropped into any project without re-copying fetch/typing code each time.
Usage
import { createVkClient, getAlbumPhotos, getPhotoSize, getVideos } from '@zotov/vk-connector'
const client = createVkClient({
ownerId: '-230535137',
accessToken: import.meta.env.VITE_VK_ACCESS_TOKEN,
})
const photos = await getAlbumPhotos(client, '306108786')
const cover = photos.response && getPhotoSize(photos.response, 0, 'w')
const videos = await getVideos(client) // omit albumId to get all owner videosNotes
accessTokenmust be a service access token from a standalone VK app (vk.com/apps → Create app → Standalone → Settings tab → "Service access key"), not a community/group access token — VK rejectsphotos.get/video.getfor group-auth tokens witherror_code 27("method is unavailable with group auth"). It ends up embedded in the client bundle of any static site that uses this package client-side — don't use a token with wider privileges than "read albums/videos".- VK API version defaults to
5.199; override viaapiVersionin the config. - JSONP request timeout defaults to 15000ms (
timeoutin the config) — vue-jsonp's own 5000ms default is often shorter than VK's actual response time forphotos.get, which throws a confusing<callback> is not definederror instead of a clean timeout rejection.
