为什么上述代码的最后一行不会显示当前用户的电子邮件?我试图这么做几天,我想我已经请求了正确的许可?
任何帮助都表示赞赏,甚至可以将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; ?>
答案 0 :(得分:0)
您需要扩展电子邮件权限。 https://developers.facebook.com/docs/reference/api/permissions/
您可以在API调用中传递req_perms = email