php-如何正确使用facebook作用域获取用户电子邮件?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-如何正确使用facebook作用域获取用户电子邮件?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1284字,纯文字阅读大概需要2分钟。
内容图文
![php-如何正确使用facebook作用域获取用户电子邮件?](/upload/InfoBanner/zyjiaocheng/654/73985cadfa424dd7867a9dc75aeb2f9d.jpg)
当用户在我的网站上使用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作用域获取用户电子邮件?全部内容,希望文章能够帮你解决php-如何正确使用facebook作用域获取用户电子邮件?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。