Not getting email after login through Twitter API - Yii2



I’m getting error like

Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\authclient\clients\Twitter::requestEmail

Whenever I am including 'requestEmail' => 'true', in 'authClientCollection' => [ for components in web.php


$config = [
  'components' => [
        'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
        'twitter' => [
          'class' => 'yii\authclient\clients\Twitter',
          'requestEmail' => 'true',
          'consumerKey' => 'IFxxxxxxxxvw',
          'consumerSecret' => 'ImxxxxxxxxZiPD',

UsersController.php (Controller)

class UsersController extends CommonController 
    public function actions() {
    return [
      'auth' => [
        'class' => 'yii\authclient\AuthAction',
        'successCallback' => [$this, 'oAuthSuccess'],

    public function oAuthSuccess($client) {
      // get user data from client
      $userAttributes = $client->getUserAttributes();
      var_dump($userAttributes); die;
      // do some thing with user data. for example with $userAttributes['email']


login.php (View)

<p class="text-center">
    <?= yii\authclient\widgets\AuthChoice::widget([
        'baseAuthUrl' => ['/users/users/auth']
   ]) ?>

But, as soon I’m omitting the line 'requestEmail' => 'true', from web.php. It’s working. I’m getting all required data except email. But, problem is : I am not getting email of user trying to login. Any idea, how can i get. Any hint/suggestion will be a great help for me. Thanks.


This looks like it is specifically related to the Yii framework. I’m not familiar with it in detail, but the documentation suggests that requestEmail is available since version 2.0.6?


Also, remember that you’ll need to have had your application keys whitelisted for access to user email addresses. I think the error you’re seeing is related to the PHP class missing properties, though.


Hi @andypiper : Yes. It is related to Yii Framework. I got mail regarding “Request Email Access Granted”. I followed Each and every step of it. I Really don’t know about this link [Verify Credentials]. It is generating “OAuth Signing Results”. See, don’t mind. I am new to it. so asking silly questions. What to do with “OAuth Signing Results” ? Means, where to keep it. Please help. I am very desperate to get email of logged in user. Without it, I can’t code forward.


I’d suggest ensuring you’re using the right version of Yii, and if it is not working either raising a support request directly with the Yii Framework folks, or switch to another PHP solution like @abraham or @jublonet libraries which are known to support retrieving the email address.


And, regarding error. Class is being included in web.php -> “yii\authclient\clients\Twitter”.


Thanks For Your Help @andypiper .
Did few modification in Twitter class, and it started working.