PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-如何正确使用facebook作用域获取用户电子邮件?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

用户在我的网站上使用Facebook登录时,我需要检索用户的电子邮件. Facebook在其登录URL中有一个scope参数,用于请求这些扩展权限.我到底要在此代码添加什么内容,以正确设置范围以包括电子邮件?@H_618_1@

/**
* 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));
}

解决方法:@H_618_1@

添加范围参数:@H_618_1@

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作用域获取用户电子邮件?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: