Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
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']);
}
}
//...
}
1. Authorize via oAuth yii2-authclient https://github.com/yiisoft/yii2-authclient
2. Use curl to work with vk api
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question