简体   繁体   English

在应用程序内的页面之间移动时访问Facebook signed_request? $ facebook-> getSignedRequest()

[英]Access the Facebook signed_request when moving between pages inside an application? $facebook->getSignedRequest()

I am installing an application inside of a Facebook page. 我正在Facebook页面中安装一个应用程序。 I received the signed_request variable in my $_REQUEST, or when using the Facebook PHP SDK Facebook::getSignedRequest() function. 我在$ _REQUEST中收到了signed_request变量,或者在使用Facebook PHP SDK Facebook :: getSignedRequest()函数时收到了。 However, inside my application when I go to a different page within the application, the signed_request does not follow it. 但是,在我的应用程序中,当我转到应用程序中的不同页面时,signed_request不会遵循它。

I understand that it is placed inside the $_SESSION and the signed_request data is stored inside the session, but what method am I supposed to be calling in order to get that data? 我知道它放在$ _SESSION中,而signed_request数据存储在会话中,但我应该调用哪种方法来获取数据? Do I have to strip it out of my session myself and not use the PHP SDK? 我是否必须自己将其从会话中删除而不使用PHP SDK? I would expect getSignedRequest to always give me the same result as long as I am receiving it in the $_REQUEST or through the $_SESSION. 我希望getSignedRequest总是给我相同的结果,只要我在$ _REQUEST或$ _SESSION中收到它。

Please advise! 请指教! Thanks in advance! 提前致谢!

I believe the issue here is with third party cookies and it's something I've come across a lot. 我相信这里的问题是第三方cookie,这是我经常遇到的问题。

The way I have solved it in the past is to check on initial load for the signed request and if present, append the raw signed request data to a query var on all links (ie http://www.example.com/page&signed_request=<<signed_request>> ) 我过去解决它的方法是检查已签名请求的初始加载,如果存在,则将原始签名请求数据附加到所有链接上的查询var(即http://www.example.com/page&signed_request=<<signed_request>>

It's not pretty but your urls are hidden from view as they are in the iframe - it's not something I would advise to do if your application isn't inside an iframe. 它并不漂亮,但是你的网址在iframe中是隐藏的 - 如果你的应用程序不在iframe中,我不建议这样做。

You will also need to check any Javascript or server side code that may affect data inside the request and amend your urls accordingly. 您还需要检查可能影响请求中的数据的任何Javascript或服务器端代码,并相应地修改您的URL。

I hope there's a better way of working than this, but it's the only way I've figured out so far (without resorting to using the app_data query var on facebook urls for navigation). 我希望有一种比这更好的工作方式,但这是我到目前为止唯一的解决方法(不使用facebook网址上的app_data查询var进行导航)。

How about saving the signedRequest in a Session and reusing it? 如何在会话中保存signedRequest并重用它?

$signedRequest = $facebook->getSignedRequest();
if(isset($signedRequest)) $_SESSION['signedRequest'] = $signedRequest;
else $signedRequest = $_SESSION['signedRequest'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM