当用户通过yahoo app登录时,从yahoo获取用户电子邮件

问题描述 投票:1回答:1

有没有办法检索用户的电子邮件地址。我正在使用混合身份验证。登录工作没有获得的电子邮件地址只能访问用户ID,显示名称和显示图片。是否有任何方法可以访问用户的电子邮件地址,一切正常,除了。回复给出了一封空白电子邮件

class Yahoo extends OAuth2
 {
   protected $scope = 'sdct-r';
   protected $apiBaseUrl = 'https://social.yahooapis.com/v1/';
   protected $authorizeUrl = 'https://api.login.yahoo.com/oauth2/request_auth';
   protected $accessTokenUrl = 'https://api.login.yahoo.com/oauth2/get_token';
   protected $apiDocumentation = 'https://developer.yahoo.com/oauth2/guide/';
   protected $userId = null;
   protected function initialize()
    {
      parent::initialize();
      $this->tokenExchangeHeaders = [
        'Authorization' => 'Basic ' . base64_encode($this->clientId .  ':' . $this->clientSecret) ]; }
  protected function getCurrentUserId()
     {
      if ($this->userId) {
        return $this->userId;
     }
     $response = $this->apiRequest('me/guid', 'GET', [ 'format' => 'json']);
     $data = new Data\Collection($response);
    if (! $data->filter('guid')->exists('value')) {
        throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
    }
    return $this->userId =  $data->filter('guid')->get('value');
}
public function getUserProfile()
{
    // Retrieve current user guid if needed
    $this->getCurrentUserId();

    $response = $this->apiRequest('user/'  . $this->userId . '/profile', 'GET', [ 'format' => 'json']);

    $data = new Data\Collection($response);

    if (! $data->exists('profile')) {
        throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
    }

    $userProfile = new User\Profile();

    $data = $data->filter('profile');

    $userProfile->identifier  = $data->get('guid');
    $userProfile->firstName   = $data->get('givenName');
    $userProfile->lastName    = $data->get('familyName');
    $userProfile->displayName = $data->get('nickname');
    $userProfile->photoURL    = $data->filter('image')->get('imageUrl');
    $userProfile->profileURL  = $data->get('profileUrl');
    $userProfile->language    = $data->get('lang');
    $userProfile->address     = $data->get('location');


    if ('F' == $data->get('gender')) {
        $userProfile->gender = 'female';
    } elseif ('M' == $data->get('gender')) {
        $userProfile->gender = 'male';
    }

    // I ain't getting no emails on my tests. go figures..
    foreach ($data->filter('emails')->toArray() as $item) {
        if ($item->primary) {
          $userProfile->email         = $item->handle;
          $userProfile->emailVerified = $item->handle;
        }
    }

    return $userProfile;
}

}

php authentication yahoo yahoo-api hybridauth
1个回答
0
投票

来自Yahoo guide

除了上面给出的声明之外,扩展的配置文件范围sdpp-w还返回以下声明:

email - 用户的电子邮件ID email_verified - 布尔标志,让客户知道雅虎是否验证了给定的电子邮件地址。

请将Hybridauth升级到3.0-rc.10,这是针对雅虎提供商的问题。

查看原始公关与修复:https://github.com/hybridauth/hybridauth/pull/986

© www.soinside.com 2019 - 2024. All rights reserved.