为什么在我的Facebook应用程序中获得signed_request的未定义索引? [英] Why do I get an undefined index for signed_request in my facebook app?

查看:285
本文介绍了为什么在我的Facebook应用程序中获得signed_request的未定义索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一个测试应用程序在Facebook上学习。我正在使用Facebook开发人员的代码页面

I am attempting a test app to learn on facebook. I am using this code from the facebook developer page:

 <?php 

     $app_id = "YOUR_APP_ID";

     $canvas_page = "YOUR_CANVAS_PAGE_URL";

     $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page);

     $signed_request = $_REQUEST["signed_request"];

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

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

     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
            echo ("Welcome User: " . $data["user_id"]);
     } 
 ?>

当我运行这个我得到:

Message: Undefined index: signed_request

笨。我不知道这是否重要..当我运行它时,它使用$ auth_url并返回:

I am using this in Codeigniter. I have no idea if that matters.. When I run this it uses the $auth_url and return:

http://mydomain.com/responsepage?code=biglongstring

所以我知道我正在Facebook和获取东西...

so I know I am getting to facebook and getting something...

在该字符串中,返回的URL是一个名为code的变量。我尝试更改$ _REQUEST对象以查找代码,但它会产生相同的错误。

In that string url returned is a variable named "code." I tried to change the $_REQUEST object to look for "code" but it gives the same error.

它会在将其简要显示因为user_id元素是空的。它是空的,因为signed_request不存在于发回的URL中。

It does redirect me back to my response page after it briefly displays the error because the "user_id" element is empty. It is empty because signed_request is not present in the url sent back.

我做错了什么?应该去Facebook,要求我允许应用,显示user_id。由于某些原因,signed_request不在。

What am I doing wrong? It should go to facebook, ask for me to allow the app, display the user_id. For some reason the signed_request just isn't there.

谢谢。

编辑:我在看再次这样。在哪里实际出去使用该URL?

I'm looking at this again. Where does it ever actually go out and use that URL?

编辑:如果我手动使用$ auth_url,将其粘贴到浏览器的地址中,将其重定向到我的响应页面没有问题。当然,我没有看到一个名为signed_request的变量,只是代码,所以我不知道发生了什么。

If I use the $auth_url manually, pasting it in the address of the browser it redirects back to my response page with no problem. Of course, I did not see a variable named signed_request, just "code" so I don't know what's going on.

推荐答案

好的,您似乎在 c $ c> $ canvas_page 变量中使用您的 Canvas URL 。您需要使用 Canvas页面,如下所示: http://apps.facebook.com/appnamespace

Okay it seems that you are using your Canvas URL in the $canvas_page variable which is wrong. You need to use the Canvas Page which is something like: http://apps.facebook.com/appnamespace

这样,您的应用程序将在内部中打开iframe,Facebook将能够向您发送 signed_request

This way, your app will open inside the iframe and Facebook will be able to send you the signed_request

这篇关于为什么在我的Facebook应用程序中获得signed_request的未定义索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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