我的 Facebook 图表 URL 有问题
当尝试从 facebook graph API 访问信息时,我显然做错了一些事情,这是我页面的代码:
它获取除用户电子邮件地址之外我需要的所有内容,我知道您需要扩展权限,我已经请求了这些权限,如图所示在我下面的代码中。
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; ?>
我转储 $graph 变量数组以查看它保存的信息,结果是:
array(7) { ["id"]=> string(10) "1469088864" ["name"]=> string(10) "Jack Brown" ["first_name"]=> string(4) "Jack" ["last_name"]=> string(5) "Brown" ["username"]=> string(11) "thebestjack" ["gender"]=> string(4) "male" ["locale"]=> string(5) "en_GB" }
它不包含电子邮件地址,因此访问令牌/使用访问令牌访问图形显然存在问题。
当我在 Facebook 帐户设置中访问此应用程序下的授权应用程序时,它显示“此应用程序需要您的电子邮件地址”[电子邮件受保护]"
I'm obviously doing something wrong when trying to access information from the facebook graph API, here is the code of my page:
It fetches everything I need other than the users email address, I understand you need extended permissions which I have requested as seen in my code below.
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; ?>
I dumped the $graph variable array to see what information it held, this was the result:
array(7) { ["id"]=> string(10) "1469088864" ["name"]=> string(10) "Jack Brown" ["first_name"]=> string(4) "Jack" ["last_name"]=> string(5) "Brown" ["username"]=> string(11) "thebestjack" ["gender"]=> string(4) "male" ["locale"]=> string(5) "en_GB" }
It doesn't contain the email address so there is obviously a problem with the access token / using the access token to access the graph.
When I go to my authorised apps on my Facebook account settings under this app it says "this apps needs your email address "[email protected]"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何请求,您都有一个
$_REQUEST["signed_request"]
,无论用户是否授权您的应用。即使根本没有登录 Facebook 的用户也可以使用它。使用 php-sdk 检索用户的个人资料 http://developers.facebook.com/文档/参考/php/facebook-api/
you have a
$_REQUEST["signed_request"]
for any request, doesn't matter if user authorized your app or not. you have it even for users who are not logged in to Facebook at all.use php-sdk to retrieve user's profile http://developers.facebook.com/docs/reference/php/facebook-api/