PHP code example of labile / kphp-vk-utils

1. Go to this page and download the library: Download labile/kphp-vk-utils 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/ */

    

labile / kphp-vk-utils example snippets


use Astaroth\VkUtils\Client;

$api = new Client;

$response = $api->request('wall.get', ['owner_id' => 1]);

use Astaroth\VkUtils\Client;
use Astaroth\VkUtils\Requests\Request;

$api = new Client;

$request = new Request('wall.get', ['owner_id' => 1]);
$response = $api->send($request);

use Astaroth\VkUtils\Execute;
use Astaroth\VkUtils\Requests\Request;

$api = new Execute;
$api->setDefaultToken('PUT ACCESS TOKEN');
$execute = [
    new Request('wall.get', ['owner_id' => 1]),
    new Request('wall.get', ['owner_id' => 2]),
    // ...more request
    new Request('wall.get', ['owner_id' => 25]),
    ];

$response = $api->send($execute);

use Astaroth\VkUtils\Client;

$api = new Client('5.131');

use Astaroth\VkUtils\Client;

$api = new Client();

$api->setDefaultToken("PUT TOKEN");

use Astaroth\VkUtils\Requests\Request;
use Astaroth\VkUtils\Client;

$api = new Client;

// The token in the request takes precedence over setDefaultToken
$request = new Request('wall.get', ['owner_id' => 1], "some_token");

use Astaroth\VkUtils\Builders\Attachments\Message\Graffiti;
use Astaroth\VkUtils\Builders\Attachments\Photo;
use Astaroth\VkUtils\Builders\Attachments\Video;
use Astaroth\VkUtils\Uploader;
use Astaroth\VkUtils\Builders\Attachments\Message\AudioMessage;

$uploader = new Uploader();
$uploader->setDefaultToken('PUT TOKEN');

$attachments = $uploader->upload
(
    new Photo("dog.jpg"),

    new AudioMessage('meow.mp3'),
    
    //downloading from the link temporarily does not work
    (new Video('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4'))
        ->setName('4 Biggers Escapes')
        ->setDescription('The video has nothing interesting, just an example')
        ->setWallpost(true),

    new Graffiti('cat.png')
);


use Astaroth\VkUtils\Builders;
use Astaroth\VkUtils\Builders\Message;
use Astaroth\VkUtils\Builders\Post;

$token = 'PUT TOKEN';

$builder = new \Astaroth\VkUtils\Builder();

$builders[] = (new Message)
    ->setMessage("hi me name is lola! im lol")
    ->setPeerId(418618);

$builders[] = (new Post)
    ->setMessage("hello subscribers")

$response = $builder->create(...$builders)
);