PHP code example of jumper423 / yii2-vk

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

    

jumper423 / yii2-vk example snippets


'components' => [
    'vk' => [
        'class' => 'jumper423\VK',
        'clientId' => '11111',
        'clientSecret' => 'n9wsv98svSD867SA7dsda87',
        'delay' => 0.7, // Минимальная задержка между запросами
        'delayExecute' => 120, // Задержка между группами инструкций в очереди
        'limitExecute' => 1, // Количество инструкций на одно выполнении в очереди
        'captcha' => 'captcha', // Компонент по распознованию капчи
    ],
],
'aliases' => [
    '@actions' => '@backend/runtime/cron', // Папка куда будут складироваться очереди для cron-а
],

'components' => [
    'captcha' => [
        'class' => 'jumper423\Captcha',
        'pathTmp' => '@imagescache/captcha',
        'apiKey' => '42eab4119020dbc729f657',
    ],
    'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'vkontakte' => [
                'class' => 'jumper423\VK',
                'clientId' => '11111',
                'clientSecret' => 'n9wsv98svSD867SA7dsda87',
                'delay' => 0.7,
                'delayExecute' => 120,
                'limitExecute' => 1,
                'captcha' => 'captcha',
                'scope' => 'friends,photos,pages,wall,groups,email,stats,ads,offline,notifications', //,messages,nohttps
                'title' => 'ВКонтакте'
            ],
        ],
    ],
],
'aliases' => [
    '@actions' => '@backend/runtime/cron', // Папка куда будут складироваться очереди для cron-а
],

/**
* @var jumper423\VK $vk
*/

$vk = Yii::$app->vk;

или

$vk = Yii::$app->authClientCollection->getClient('vkontakte');

$response = $vk->post('photos.createAlbum', ['group_id' => $groupId, 'title' => $title, 'upload_by_admins_only' => 1]);

foreach ($images as $image) {
    $vk->addAction('photos.edit', ['caption' => $caption, 'owner_id' => $ownerId, 'photo_id' => $image,]);
}
// Добавление в cron
$vk->addActionsInCron('photos.edit');
// Или начать выполнение очереди командой
// $vk->performAnAction();

$vk->performAnActionFromCron('photos.edit');

$imageId = $vk->loadImage($imagePath, $albumId, $groupId);

$data = $webDriver->getData($this->api->getOauthUri());
if (!count($data)) {
    throw new Exception('Ошибка при авторизации');
}
$token = [
    'tokenParamKey' => 'access_token',
    'tokenSecretParamKey' => 'oauth_token_secret',
    'createTimestamp' => time(),
    'params' => $data,
];
$this->vk->vk_id = $data['user_id'];
$this->vk->token = $token;
$this->vk->save();
$this->api->setToken($this->vk->token);

/**
 * @param $url string
 * @param $recursia bool
 */
public function getData($url, $recursia = true)
{
    $this->driver->get($url);
    $this->driver->findElement(WebDriverBy::name('email'))->sendKeys($this->vkTable->login);
    $this->driver->findElement(WebDriverBy::name('pass'))->sendKeys($this->vkTable->password);
    $this->driver->findElement(WebDriverBy::id('install_allow'))->click();
    sleep(3);
    while ($this->driver->findElements(WebDriverBy::xpath('//input[@name=\'captcha_key\']'))) {
        $this->captcha();
        $this->driver->findElement(WebDriverBy::name('pass'))->sendKeys($this->vkTable->password);
        $this->driver->findElement(WebDriverBy::id('install_allow'))->click();
        sleep(3);
    }
    $this->driver->wait(60, 1000)->until(
        WebDriverExpectedCondition::titleContains('VK | Request Access')
    );
    $this->driver->findElement(WebDriverBy::id('install_allow'))->click();
    $this->driver->wait(60, 1000)->until(
        WebDriverExpectedCondition::titleContains('OAuth Blank')
    );
    $urlCurrent = $this->driver->getCurrentURL();
    $parseUrl = parse_url($urlCurrent);
    if (!isset($parseUrl['fragment']) && $recursia == true) {
        return $this->getData($url, false);
    }
    $query = $parseUrl['fragment'];
    parse_str($query, $data);
    return $data;
}

php composer.phar