为什么这行不通? - 它不会显示用户的电子邮件地址

发布于 2024-12-27 00:11:44 字数 1942 浏览 1 评论 0原文

为什么上面代码的最后一行不显示当前用户的电子邮件?我已经尝试这样做好几天了,我想我已经请求了正确的许可吗?

感谢任何帮助,甚至可以在 PayPal 上分享几英镑/美元给可以帮助我摆脱困境的人!

 <?php
/**
 * Copyright 2011 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

require 'src/facebook.php';
$app_id = "211665122244023";


     $canvas_page = "http://apps.facebook.com/midcitymafia/";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,publish_actions";

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

$user_id = $data["user_id"];
     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
                         $graph1 = file_get_contents ("https://graph.facebook.com/".$user_id . "/?accesstoken=" . $data["oauth_token"]);
         $graph=json_decode($graph1,true);
     }



$userid =  $user_id;
$username = $graph['name'];
$usergender = $graph['gender'];
$useremail = $graph['email'];

?>

<br>

<?php echo 'ID: ' . $userid; ?>
<br>
<?php echo 'Name: ' . $username; ?>
<br>
<?php echo 'Gender: ' . $usergender; ?>
<br>
<?php echo 'Email: ' . $useremail; ?>

Why won't the last line of the above code show the email for the current user? Have being trying to do this for days, I think I have requested the right permission's?

Any help is appreciated, might even share a few pound / dollars on PayPal to the person who can help me get out of this mess!

 <?php
/**
 * Copyright 2011 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

require 'src/facebook.php';
$app_id = "211665122244023";


     $canvas_page = "http://apps.facebook.com/midcitymafia/";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,publish_actions";

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

$user_id = $data["user_id"];
     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
                         $graph1 = file_get_contents ("https://graph.facebook.com/".$user_id . "/?accesstoken=" . $data["oauth_token"]);
         $graph=json_decode($graph1,true);
     }



$userid =  $user_id;
$username = $graph['name'];
$usergender = $graph['gender'];
$useremail = $graph['email'];

?>

<br>

<?php echo 'ID: ' . $userid; ?>
<br>
<?php echo 'Name: ' . $username; ?>
<br>
<?php echo 'Gender: ' . $usergender; ?>
<br>
<?php echo 'Email: ' . $useremail; ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦亦如幻 2025-01-03 00:11:44

您将需要电子邮件的扩展权限。
https://developers.facebook.com/docs/reference/api/permissions/

您可以在 API 调用中传递 req_perms=email

You will need extended permissions for email.
https://developers.facebook.com/docs/reference/api/permissions/

You can pass req_perms=email in the API call

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文