PHP code example of vk / php-sdk
1. Go to this page and download the library: Download vk/php-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vk / php-sdk example snippets
$vk = new VKAPIClient();
$oauth = new VKOAuth();
$oauth->authorize('{client_id}', '{redirect_uri}', '{display}', '{scope_array}',
OAuthResponseType::CODE, '{api_version}', '{state}');
$oauth->authorize(6125390, 'http://example.com', OAuthDisplay::POPUP, array(OAuthUserScope::AUDIO, OAuthUserScope::DOCS),
OAuthResponseType::CODE, '5.69', 'some state');
$access_token = $oauth->getAccessToken('{client_id}', '{client_secret}', '{redirect_uri}', '{code}');
$access_token = $oauth->getAccessToken(6125390, 'Dv3Ef3srY3d2GE1c1X0F', 'http://example.com', '4g2h79rd3f7580a23d');
$users = array(1, 210700286);
$fields = array('city', 'photo');
$response = $vk->users()->get($access_token, array(
'user_ids' => $users,
'fields' => $fields
)
);
$address = $vk->photos()->getMessagesUploadServer('{access_token}');
$photo = $vk->request()->upload($address['upload_url'], 'photo', '/Users/Me/Documents/Photos/my_photo.jpg');
$response_save_photo = $vk->photos()->saveMessagesPhoto($access_token, array(
'server' => $photo['server'],
'photo' => $photo['photo'],
'hash' => $photo['hash']
)
);
$address = $vk->video()->save($access_token, array(
'name' => 'My video',
)
);
$video = $vk->request()->upload($address['upload_url'], 'video_file', '/Users/Me/Documents/Videos/my_video.mp4');
$vk->groups()->setLongPollSettings($access_token, array(
'group_id' => 159895463,
'enabled' => 1,
'message_new' => 1,
'wall_post_new' => 1,
));
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']);
}
}
$handler = new CallbackApiMyHandler();
$executor = new CallbackApiLongPollExecutor($vk, '{access_token}', '{$group_id}', $handler, '{$wait}');
$executor->listen();
$executor = new CallbackApiLongPollExecutor($vk, $access_token, 159895463, $handler, 25);
$executor->listen(12);