In order to use VKontakte OAuth you must register your application at .
Example application configuration:
~~~
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'vkontakte' => [
'class' => 'yii\authclient\clients\VKontakte',
'clientId' => 'vkontakte_client_id',
'clientSecret' => 'vkontakte_client_secret',
],
],
]
...
]
~~~
/** * @inheritdoc */ public function api($apiSubUrl, $method = 'GET', array $params = [], array $headers = [], $delay = false) { $this->sleep($delay); $response = parent::api($apiSubUrl, $method, $params, $headers); if (ArrayHelper::getValue($response, 'error.error_code') == 14 && $this->captcha) { if ($this->captcha->run(ArrayHelper::getValue($response, 'error.captcha_img'))) { $response = $this->api($apiSubUrl, $method, ArrayHelper::merge($params, ['captcha_sid' => ArrayHelper::getValue($response, 'error.captcha_sid'), 'captcha_key' => $this->captcha->result()]), $headers); } else { throw new Exception($this->captcha->error()); } } elseif (ArrayHelper::getValue($response, 'error')) { throw new Exception(ArrayHelper::getValue($response, 'error.error_msg'), ArrayHelper::getValue($response, 'error.error_code')); } return $response; }
/** * @inheritdoc */ public function __construct($config = []) { parent::__construct($config); if (is_string($this->captcha)) { if (Yii::$app->has($this->captcha) && Yii::$app->get($this->captcha) instanceof CaptchaInterface) { $this->captcha = Yii::$app->get($this->captcha); } else { $this->captcha = null; } } elseif (is_object($this->captcha)) { if (!$this->captcha instanceof CaptchaInterface) { $this->captcha = null; } } else { $this->captcha = null; } }
/** * @inheritdoc * This method adds lang param to each api call */ public function apiInternal($accessToken, $url, $method, array $params, array $headers) { $params['lang'] = Yii::$app->language === 'ru' ? 'ru' : 'en'; return \yii\authclient\clients\VKontakte::apiInternal($accessToken, $url, $method, $params, $headers); }
public function init() { parent::init(); }
/** * @param int $limit * * @return array * @throws Exception */ public function getPosts($limit = 100) { return $this->parseGetPosts($this->service->api($this->getWallGetRequestUrl($limit), 'GET'), 'response', ['id', 'text'], ['service_id_author' => 'from_id', 'service_id_post' => 'id', 'time_created' => 'date', 'content' => 'text']); }