gpt4 book ai didi

php - 如何正确使用 facebook scope 获取用户邮箱?

转载 作者:搜寻专家 更新时间:2023-10-31 20:51:42 24 4
gpt4 key购买 nike

当用户在我的网站上使用 facebook 登录时,我需要检索用户的电子邮件。 Facebook 在其登录 URL 中有一个 scope 参数,用于请求这些扩展权限。我到底应该向这段代码添加什么才能正确设置范围以包含电子邮件?

/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*
* @param Array $params provide custom parameters
* @return String the URL for the login flow
*/
public function getLoginUrl($params=array()) {
$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
'client_id' => $this->getAppId(),
'redirect_uri' => $currentUrl, // possibly overwritten
'state' => $this->state),
$params));
}

最佳答案

添加作用域参数:

public function getLoginUrl($params=array()) {
$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
'client_id' => $this->getAppId(),
'redirect_uri' => $currentUrl, // possibly overwritten
'state' => $this->state,
'scope'=>'email'),
$params));
}

关于php - 如何正确使用 facebook scope 获取用户邮箱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6780301/

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