1. Go to this page and download the library: Download programmis/php-vk-api-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/ */
programmis / php-vk-api-sdk example snippets
$server = new PhotosGetUploadServer($token);
$server->setAlbumId($album_id)
->setGroupId($group_id);
if (!$server->doRequest()) {
return;
}
if (!$server->upload([$img_path])) {
return;
}
$uploadResult = $server->getUploadResult();
$photos = new PhotosSave($token);
$photos->setAlbumId($album_id)
->setGroupId($group_id)
->setServer($uploadResult->getServer())
->setPhotosList($uploadResult->getPhotosList())
->setHash($uploadResult->getHash())
->setCaption($text);
if (!$photos->doRequest()) {
return;
}
$joinGroup = new GroupsJoin();
$joinGroup->setGroupId(1);
if( $joinGroup->doRequest()){
echo $joinGroup->getResponse();
}
$wallPost = new WallPost();
$wallPost->setOwnerId(1)
->setMessage("test");
if($wallPost->doRequest()){
echo $wallPost->getPostId();
}
$album = new PhotosCreateAlbum();
$album->setTitle("My new test album");
if($album->doRequest()){
echo $album->getAlbumInfo()->getId();
}
$friendsAdd = new FriendsAdd();
$friendsAdd->setUserId(1)
->setText("Add me please");
if($friendsAdd->doRequest()){
switch($friendsAdd->getResponse()){
case FriendsAdd::RESULT_SEND:
case FriendsAdd::RESULT_ACCEPT:
case FriendsAdd::RESULT_REPEAT:
echo "OK";
break;
}
}
$statusSet = new StatusSet();
$statusSet->setText("This is my new status");
if($statusSet->doRequest()){
echo $statusSet->getResponse();
}
$boardComment = new BoardCreateComment();
$boardComment->setMessage("This is my new comment")
->setGroupId(1)
->setTopicId(21972158);
if ($boardComment->doRequest()) {
echo $boardComment->getCommentId();
}
$online = new AccountSetOnline();
if($online->doRequest()){
echo $online->getResponse();
}
$poll = new PollsCreate();
$poll->setOwnerId(1)->setIsAnonymous(1)
->setQuestion("Would you like to provide financial assistance for a set of these classes?")
->addAnswer('Yes')
->addAnswer('Of course');
if($poll->doRequest()){
echo $poll->getPollInfo()->getId() . "\n";
}
$antiCaptcha = new \AntiCaptcha\RuCaptcha(); //integrated in project now
$antiCaptcha->setAccessToken($anti_captcha_access_token);
\VkSdk\Includes\Request::setAntiCaptcha($antiCaptcha);