PHPackages                             vk/php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vk/php-sdk

ActiveLibrary

vk/php-sdk
==========

VK SDK for PHP

v1.0(8y ago)1280MITPHPPHP &gt;=5.4

Since Jan 30Pushed 8y ago1 watchersCompare

[ Source](https://github.com/erokhinav/vk-php-sdk)[ Packagist](https://packagist.org/packages/vk/php-sdk)[ Docs](https://github.com/erokhinav/vk-php-sdk)[ RSS](/packages/vk-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

vk-php-sdk
==========

[](#vk-php-sdk)

PHP library for VK API interaction, includes OAuth 2.0 authorization and API methods. Full VK API features documentation can be found [here](http://vk.com/dev).

This library has been created using the VK API JSON Schema. It can be found [here](https://github.com/VKCOM/vk-api-schema). It uses VK API [version](https://vk.com/dev/versions) 5.69.

1. Installation
---------------

[](#1-installation)

The VK PHP SDK can be installed using Composer by running the following command:

```
composer require vk/php-sdk
```

2. Initialization
-----------------

[](#2-initialization)

Create VKAPIClient object using the following code:

```
$vk = new VKAPIClient();
```

3. Authorization
----------------

[](#3-authorization)

The library provides the authorization flows for user based on OAuth 2.0 protocol implementation in vk.com API. Please read the full [documentation](https://vk.com/dev/access_token) before you start.

### 3.1. Authorization Code Flow for User

[](#31-authorization-code-flow-for-user)

OAuth 2.0 Authorization Code Flow allows calling methods from the server side.

This flow includes two steps — obtaining an authorization code and exchanging the code for an access token. Primarily you should obtain the "code" ([manual](https://vk.com/dev/authcode_flow_user)) by redirecting the user to the authorization page using the following method:

```
$oauth = new VKOAuth();

$oauth->authorize('{client_id}', '{redirect_uri}', '{display}', '{scope_array}',
    OAuthResponseType::CODE, '{api_version}', '{state}');
```

As a '{display}' you should pass a constant from the OAuthDisplay class. The '{scope\_array}' should be an array of constants from the OAuthUserScope class.

Example:

```
$oauth->authorize(6125390, 'http://example.com', OAuthDisplay::POPUP, array(OAuthUserScope::AUDIO, OAuthUserScope::DOCS),
    OAuthResponseType::CODE, '5.69', 'some  state');
```

After successful authorization user's browser will be redirected to the specified **redirect\_uri**. Meanwhile the code will be sent as a GET parameter to the specified address:

```
REDIRECT_URI?code=CODE
```

Then use this method to get the access token:

```
$access_token = $oauth->getAccessToken('{client_id}', '{client_secret}', '{redirect_uri}', '{code}');
```

The '{redirect\_uri}' should be the URL that was used to get a code at the first step.

Example:

```
$access_token = $oauth->getAccessToken(6125390, 'Dv3Ef3srY3d2GE1c1X0F', 'http://example.com', '4g2h79rd3f7580a23d');
```

4. API Requests
---------------

[](#4-api-requests)

You can find the full list of VK API methods [here](https://vk.com/dev/methods).

### Request sample

[](#request-sample)

Example of calling method **users.get**:

```
$users = array(1, 210700286);
$fields = array('city', 'photo');

$response = $vk->users()->get($access_token, array(
    'user_ids' => $users,
    'fields' => $fields
    )
);
```

### Uploading Photos into a Private Message

[](#uploading-photos-into-a-private-message)

Please read [the full manual](https://vk.com/dev/upload_files?f=4.%20Uploading%20Photos%20into%20a%20Private%20Message) before the start.

Call **photos.getMessagesUploadServer** to receive an upload address:

```
$address = $vk->photos()->getMessagesUploadServer('{access_token}');
```

Then use **upload()** method to send files to the **upload\_url** address received in the previous step:

```
$photo = $vk->request()->upload($address['upload_url'], 'photo', '/Users/Me/Documents/Photos/my_photo.jpg');
```

You will get a JSON object with **server**, **photo**, **hash** fields. To save a photo call **photos.saveMessagesPhoto** with these three parameters:

```
$response_save_photo = $vk->photos()->saveMessagesPhoto($access_token, array(
    'server' => $photo['server'],
    'photo' => $photo['photo'],
    'hash' => $photo['hash']
    )
);
```

Then you can use **'owner\_id'** and **'id'** parameters from the last response to create an attachment of the uploaded photo.

### Uploading Video Files

[](#uploading-video-files)

Please read [the full manual](https://vk.com/dev/upload_files_2?f=9.%20Uploading%20Video%20Files) before the start.

Call **video.save** to get a video upload server address:

```
$address = $vk->video()->save($access_token, array(
    'name' => 'My video',
    )
);
```

Send a file to **upload\_url** received previously calling **upload()** method:

```
$video = $vk->request()->upload($address['upload_url'], 'video_file', '/Users/Me/Documents/Videos/my_video.mp4');
```

Videos are processed for some time after uploading.

6. Callback API LongPoll handler
--------------------------------

[](#6-callback-api-longpoll-handler)

Enable Callback API LongPoll for your group and specify which events should be tracked by calling the following API method:

```
$vk->groups()->setLongPollSettings($access_token, array(
   'group_id' => 159895463,
   'enabled' => 1,
   'message_new' => 1,
   'wall_post_new' => 1,
));
```

Override methods from CallbackApiHandler class for handling events:

```
class CallbackAPIMyHandler extends CallbackApiHandler {
    public function messageNew($object) {
        var_dump('New message: ' . $object['body']);
    }

    public function wallPostNew($object) {
        var_dump('New wall post: ' . $object['text']);
    }
}
```

To start listening to LongPoll events, create an instance of your CallbackAPIMyHandler class, instance of CallbackApiLongPollExecutor class and call method run():

```
$handler = new CallbackApiMyHandler();
$executor = new CallbackApiLongPollExecutor($vk, '{access_token}', '{$group_id}', $handler, '{$wait}');
$executor->listen();
```

Parameter '{wait}' is the waiting period.

While calling function **listen()** you can also specify the number of the event from which you want to receive data. The default value is the number of the last event.

Example:

```
$executor = new CallbackApiLongPollExecutor($vk, $access_token, 159895463, $handler, 25);
$executor->listen(12);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3021d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cf2a4f718a8bb4aa23a7743f76f942f5cbf5b8e80696466fe4ca187788a6d0c?d=identicon)[erokhinav](/maintainers/erokhinav)

---

Top Contributors

[![erokhinav](https://avatars.githubusercontent.com/u/11597172?v=4)](https://github.com/erokhinav "erokhinav (98 commits)")[![tsivarev](https://avatars.githubusercontent.com/u/1080768?v=4)](https://github.com/tsivarev "tsivarev (1 commits)")

---

Tags

sdkvk

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vk-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/vk-php-sdk/health.svg)](https://phpackages.com/packages/vk-php-sdk)
```

###  Alternatives

[vkcom/vk-php-sdk

VK PHP SDK

213803.4k17](/packages/vkcom-vk-php-sdk)[bocharsky-bw/vkontakte-php-sdk

Vkontakte PHP SDK

3259.2k1](/packages/bocharsky-bw-vkontakte-php-sdk)[digitalstars/simplevk

Powerful PHP library/framework for VK API bots, supporting LongPoll &amp; Callback &amp; OAuth

883.9k3](/packages/digitalstars-simplevk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
