gpt4 book ai didi

Yii2 authclient 不返回用户的电子邮件 ID

转载 作者:行者123 更新时间:2023-12-01 05:13:40 24 4
gpt4 key购买 nike

我正在使用 yii2-authclient 登录我的网站,收到这样的回复

yii\authclient\clients\Facebook Object ( [authUrl] => https://www.facebook.com/dialog/oauth?display=popup [tokenUrl] => https://graph.facebook.com/oauth/access_token [apiBaseUrl] => https://graph.facebook.com [scope] => email [version] => 2.0 [clientId] => *******[clientSecret] => ********[_returnUrl:yii\authclient\BaseOAuth:private] => http://www.usermodule.com/index.php?r=site%2Fauth&authclient=facebook [_curlOptions:yii\authclient\BaseOAuth:private] => Array ( ) [_accessToken:yii\authclient\BaseOAuth:private] => yii\authclient\OAuthToken Object ( [tokenParamKey] => access_token [tokenSecretParamKey] => oauth_token_secret [createTimestamp] => 1436772538 [_expireDurationParamKey:yii\authclient\OAuthToken:private] => [_params:yii\authclient\OAuthToken:private] => Array ( [access_token] => ****************************** [expires] => 5182933 ) ) [_signatureMethod:yii\authclient\BaseOAuth:private] => Array ( ) [_id:yii\authclient\BaseClient:private] => facebook [_name:yii\authclient\BaseClient:private] => [_title:yii\authclient\BaseClient:private] => [_userAttributes:yii\authclient\BaseClient:private] => [_normalizeUserAttributeMap:yii\authclient\BaseClient:private] => [_viewOptions:yii\authclient\BaseClient:private] => [_events:yii\base\Component:private] => Array ( ) [_behaviors:yii\base\Component:private] => ) Array ( [name] => **** [id] => *****)

这是我的配置

 'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => '***',
'clientSecret' => '****',

],
],
]

我能够获取用户名、用户 ID,但不能获取用户电子邮件 ID,为什么?我还应该做什么?

最佳答案

是的,终于得到了解决方案,

当您发出图形 API 请求时

$this->makeSignedRequest('me');

替换为

$this->makeSignedRequest('me?fields=id,name,email');

要么你正在使用 facebook sdk,要么像我一样使用 yii2-eauth 扩展。如果你正在使用 yii2-eauth 那么你需要在 vendor/nodge/yii2-eauth/src/services/FacebookOAuth2Service.php 中更改它

然后添加这一行来读取电子邮件属性

$this->attributes['email'] = $info['email'];

注意:我试过 yii 传递参数的方式,比如

$this->makeSignedRequest('me',array('fields'=>'id,email');

对我不起作用。

解决方案来源: https://developers.facebook.com/docs/php/howto/example_retrieve_user_profile/5.0.0

关于Yii2 authclient 不返回用户的电子邮件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31377753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com