S
S
Space2015-05-27 07:16:15
Yii
Space, 2015-05-27 07:16:15

How to use VK API in Yii2?

I can't find examples of working with the VK API through yii. Conditionally I want to pull out the id of a person and put it in the database. I don't understand how to do this. Explain on your fingers please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander N++, 2015-05-27
@ruslite

Addition to the first answer above, a practical example in the forehead.

public $enableCsrfValidation = false;

  public function actions()
  {
    return [
      'social' => [
        'class' => 'yii\authclient\AuthAction',
        'successCallback' => [$this, 'successCallback'],
      ],
    ];
  }

/**
   * @param $client
   */
  public function successCallback($client)
  {
        $day = 86400;
    $client_id = Yii::$app->request->get('authclient');
    $attributes = $client->getUserAttributes();

        // VK
    if($client instanceof VKontakte)
    {
      $auth_params = $client->getAccessToken()->getParams();
      $email = ArrayHelper::getValue($auth_params,'email','');
            // Аватарка из VK да ПОБОЛЬШЕ!!!
            $vk_data_response = $client->api('users.get','POST',['uids'=>  $attributes['id'] , 'fields'=> 'photo_max_orig']);
            if($vk_data_response = ArrayHelper::getValue($vk_data_response,'response',false))
            {
                $vk_data = array_shift($vk_data_response);
                Yii::$app->session->setFlash('social_avatar', $vk_data['photo_max_orig']);
            }
    }

//...
}

A
Alexey Volegov, 2015-05-27
@EagleMoor

1. Authorize via oAuth yii2-authclient https://github.com/yiisoft/yii2-authclient
2. Use curl to work with vk api

V
Vlad Pasechnik, 2015-10-25
@jumper423

ComponentYii2 API

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question