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', ], ], ] ... ] ~~~
See also: http://vk.com/apps.php?act=add&site=1
See also: http://vk.com/developers.php?oid=-1&p=users.get
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\authclient\OAuth2
Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * @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;
     }
 }
Exemplo n.º 3
0
 /**
  * @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);
 }
Exemplo n.º 4
0
 public function init()
 {
     parent::init();
 }
Exemplo n.º 5
0
 /**
  * @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']);
 }