我是facebook应用程序的新手,我正在使用facebook的php jdk中的示例代码进行测试。虽然我得到了用户名,名字等,但我没有收到电子邮件或生日信息。我在这个论坛How to get Users Email Id in Facebook application using PHP?中搜索并添加了额外的行'req_perms' =>'email,user_birthday,publish_stream'
,但结果是一样的。我发给你代码:
public function getLoginUrl($params=array()) {
$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
'client_id' => $this->getAppId(),
'req_perms' =>'email,user_birthday,publish_stream',
'redirect_uri' => $currentUrl, // possibly overwritten
'state' => $this->state),
$params));
/**
* Get a Logout URL suitable for use with redirects.
*
* The parameters:
* - next: the url to go to after a successful logout
*
* @param array $params Provide custom parameters
* @return string The URL for the logout flow
*/
public function getLogoutUrl($params=array()) {
return $this->getUrl(
'www',
'logout.php',
array_merge(array(
'next' => $this->getCurrentUrl(),
'access_token' => $this->getAccessToken(),
), $params)
);
}
在index.php
我检索电子邮件
echo "E-mail".$user_profile['email']."<br />";
答案 0 :(得分:0)
您已更改了facebook sdk库。您已编辑了facebook.php的代码。无需编辑facebook库的代码。只需从facebook库中删除参数:
'req_perms' =>'email,user_birthday,publish_stream',
您必须在此处使用此参数:
$loginUrl = $facebook->getLoginUrl(array('canvas' => 1,
'fbconnect' => 0,
'scope' => 'email,user_birthday,publish_stream',
'next' => CANVAS_PAGE,
'cancel_url' => CANVAS_PAGE ));
将req_perms更改为范围。现在它将正常工作