未定义索引错误,$code = $_REQUEST[“code”];用于 Facebook 身份验证
每次我进入 Facebook 应用程序的画布页面时,都会短暂显示一条错误,指出 $code = $_REQUEST["code"]; 行上未定义索引;在第 9 行。此代码显示后,看起来它执行了快速重定向,并且一切正常。有谁知道如何解决这个问题?这是我在画布顶部的代码:
<?php
$app_id = "244958008880978";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "https://apps.facebook.com/guessyguesser/";
session_register();
session_start();
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
{
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
}
?>
谢谢!
Every time I go to the canvas page of my facebook app it briefly shows an error saying undefined index on the line with $code = $_REQUEST["code"]; at line 9. After this code shows it looks like it does a quick redirect and everything works fine. Does anyone know how to solve this? Here's my code at the top of the canvas:
<?php
$app_id = "244958008880978";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "https://apps.facebook.com/guessyguesser/";
session_register();
session_start();
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
{
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
}
?>
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以在第 9 行的开头添加一个 @,或者将第 9 行移到
if
块下方,并将第 11 行更改为Oh,并在
exit
后面添加一个exit
语句。代码>回显。Either add an @ to the beginning of line 9, or move line 9 below the
if
block and change line 11 toOh, and also add an
exit
statement right after thatecho
.