Skip to content

labi-le/kphp-vk-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vk-utils

GitHub license Packagist Stars Packagist Stats

Документация на русском языке

Installation

composer require labile/kphp-vk-utils

How to use it?

Simple request

use Astaroth\VkUtils\Client;

$api = new Client;

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

Use Request class

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 ExecuteRequest class

Sending multiple requests at the same time

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);

Using the required api version

use Astaroth\VkUtils\Client;

$api = new Client('5.131');

Using a token for requests

Set default token in client

use Astaroth\VkUtils\Client;

$api = new Client();

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

or so

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");

Constructors

Attachment upload constructor

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')
);

Builder

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)
);