Skip to main content
Version: iOS 1.0.12

Video Querying Guide

VKVideos is where it all starts#

To access all videos in the library, we have a class called VKVideos that allows you to query all your videos.

To access anything in the video store you must have a session in place by calling VKSession.current.start().

You must ensure the connection state is VKSessionState.connected. This can be checked through VKSession.current.state.

Making a Query#

For making queries against our API you can use VKVideos.shared.get() method, it will return VKVideosResponse with list of videos and total videos count in their completion block.

Here are some examples:.

Get all videos:

VKVideos.shared.get(byFilter: VKVideoFilter(), sortOrder: .desc) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Get videos with tags:

let filter = VKVideoFilter()
filter.tags = ["birthday", "outdoor"]
VKVideos.shared.get(byFilter: filter, sortOrder: .asc) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Get videos with metadata:

let filter = VKVideoFilter()
filter.metadata = [
"group" : "private",
"selected" : "true"
]
VKVideos.shared.get(byFilter: filter, sortOrder: .desc) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Get some user videos:

let filter = VKVideoFilter()
// Identity is a unique string representing each user or device.
filter.identity = "max"
VKVideos.shared.get(byFilter: filter, sortOrder: .desc) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Get second page of videos and limit by 20:

let filter = VKVideoFilter()
filter.page = 2
filter.limit = 20
VKVideos.shared.get(byFilter: filter, sortOrder: .desc) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Get videos by ids:

VKVideos.shared.get(
byVideoIds: [
"1a073e79-82d0-4d09-8640-44faa6ac0906",
"5fba1709-5cd5-4fb3-9b77-7987d550f9f3"
]
) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Get only videos that passed the content filter:

Please make sure that your app token and project has content filtering enabled. Content filtering flags inappropriate content (e.g. gore or nudity).

let filter = VKVideoFilter()
filter.omitUnsafeContent = true
VKVideos.shared.get(byFilter: filter, sortOrder: .desc) { (response: VKVideosResponse?, error: Error?) in
if let videos = response?.videos {
// Use your videos
} else {
// Handle error
}
}

Available since Version 1.0.8

Last updated on by Nikita Gaer