身份验证令牌Facebook的PHP的错误 [英] Auth token facebook php error

查看:287
本文介绍了身份验证令牌Facebook的PHP的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪,因为在我的Facebook应用程序,我得到所有关于我的auth_token这些PHP错误,然后重定向我的画布页面和作品,因为它应该。谁能帮我算出这个陈健波青睐?我的继承人的PHP code。在页面的顶部:
    

  $ APP_ID =181247432419054;
$ app_secret =xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
$ my_url =htt​​ps://apps.facebook.com/wellnessq/;
了session_register();
在session_start();
如果(!使用isset($ _ REQUEST [code))
{
 $ _SESSION ['状态'] = MD5(uniqid(RAND(),TRUE)); // CSRF保护
 $ dialog_url =htt​​p://www.facebook.com/dia​​log/oauth?client_id=
   。 $ APP_ID。与& REDIRECT_URI =。 urlen code($ my_url)。 &放大器;范围=电子邮件和放大器;状态=
   。 $ _SESSION ['状态']; 回声(<脚本> top.location.href ='。$ dialog_url。'< / SCRIPT>中);
 }
 $code = $ _REQUEST ['code'];
{
 $ TOKEN_URL =htt​​ps://graph.facebook.com/oauth/access_token?
   。 CLIENT_ID =。 $ APP_ID。与& REDIRECT_URI =。 urlen code($ my_url)
   。与& client_secret =。 $ app_secret。 &放大器; code =。 $$ C $℃; $响应=的file_get_contents($ TOKEN_URL);
 $ PARAMS = NULL;
 parse_str($响应,$ params)方法; $ graph_url =htt​​ps://graph.facebook.com/me?access_token=
   。 $ PARAMS ['ACCESS_TOKEN']; $ USER = json_de code(的file_get_contents($ graph_url));
}?>

第一条错误消息在$code = $ _REQUEST ['code']开始;然后后跟几个。我不能发布的屏幕截图,因为我有太少的信誉积分= /哎呀但这里的错误信息:

注意:未定义指数:在D code:\\外网\\ www.mysite.com \\管理\\这里\\ core.functions.php(663):eval()函数'D第19行

警告: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=181247432419054&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fwellnessq%2F&client_secret=xxxxxxxxxxxxxxxxx&$c$c=) [function.file-GET-内容]:未能打开流:HTTP请求失败! HTTP / 1.0 400 D差请求:\\外网\\ www.mysite.com \\管理\\这里\\ core.functions.php(663):在第25行的eval()'D code

注意:未定义指数:D中ACCESS_TOKEN:\\外网\\ www.mysite.com \\管理\\这里\\ core.functions.php(663):在第30行的eval()'D code

警告:的file_get_contents(https://graph.facebook.com/me?access_token=)function.file-GET-内容]:未能打开流:HTTP请求失败! HTTP / 1.0 400 D差请求:\\外网\\ www.mysite.com \\管理\\这里\\ core.functions.php(663):在第32行的eval()'D code

谢谢!


解决方案

您需要添加一个退出; 语句之后,你呼应&LT ;脚本> 标记。我已经注意到了很多Facebook的样品code的这一疏忽。通常情况下它不会造成太大的问题,但一旦你已经确定你需要重定向你应该确保你停止做其他事情,并给浏览器的时间来处理重定向脚本。

It's weird because on my canvas page for my facebook app I get all these php errors about my auth_token and then it redirects and works as it should. Can someone help me figure this out por favor? Heres my php code at the top of the page:

$app_id = "181247432419054";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "https://apps.facebook.com/wellnessq/";
session_register();
session_start();


if (!isset($_REQUEST["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) . "&scope=email&state="
   . $_SESSION['state'];

 echo("<script> top.location.href='" . $dialog_url . "'</script>");
 }
 $code = $_REQUEST['code'];
{
 $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));
}

?> 

The first error message starts at $code = $_REQUEST['code']; and then is followed by a few more. I cant post a screen shot because I have too few reputation points =/ grrr But here's the error messages:

Notice: Undefined index: code in D:\Extranet\www.mysite.com\manager\here\core.functions.php(663) : eval()'d code on line 19

Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=181247432419054&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fwellnessq%2F&client_secret=xxxxxxxxxxxxxxxxx&code=) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in D:\Extranet\www.mysite.com\manager\here\core.functions.php(663) : eval()'d code on line 25

Notice: Undefined index: access_token in D:\Extranet\www.mysite.com\manager\here\core.functions.php(663) : eval()'d code on line 30

Warning: file_get_contents(https://graph.facebook.com/me?access_token=) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in D:\Extranet\www.mysite.com\manager\here\core.functions.php(663) : eval()'d code on line 32

Thanks!

解决方案

You need to add an exit; statement right after you echo the <script> tag. I have noticed this oversight in a lot of the Facebook sample code. Normally it doesn't cause much problem but once you have determined that you need to redirect you should make sure you stop doing anything else and give the browser time to process the redirect script.

这篇关于身份验证令牌Facebook的PHP的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆