php - 当用户通过雅虎应用程序登录时从雅虎获取用户电子邮件
问题描述
有什么方法可以检索用户的电子邮件地址。我正在使用混合身份验证。登录工作没有电子邮件地址获得只有访问用户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;
}
}
解决方案
来自雅虎指南:
扩展配置文件范围 sdpp-w 除了上面给出的声明外,还返回以下声明:
email - 用户的电子邮件 ID
email_verified - 让客户知道给定电子邮件地址是否已被 Yahoo 验证的布尔标志。
请将 Hybridauth 升级到3.0-rc.10,它为 Yahoo 提供商修复了该问题。
请参阅带有修复的原始 PR:https ://github.com/hybridauth/hybridauth/pull/986
推荐阅读
- scala - Scala - 如何合并 HDFS 位置的增量文件
- javascript - 如何在使用 useEffect 渲染之前填充对象
- python - IndexError:字符串索引超出范围 - Treeview
- javascript - JsPDF缩放到大小?
- android-studio - 更新到 Android Studio 4.1,flutter 插件和 dart 插件未安装
- node.js - Webpack + Sequelize:从文件中导入模型定义
- python - 如何编写恢复 cwd 的异步装饰器?
- php - 尝试让 apache 在 Linux 中通过 PHP 运行 Python 时出现 Permission denied 错误
- javascript - Modalize 不会覆盖反应导航
- python - 写入一个条目字段最终写入所有实例