开发者

Access request variables in iFrame

开发者 https://www.devze.com 2023-03-21 12:10 出处:网络
I am trying to build a multiplayer game as a Facebook app, So, in this I give one player a link , which he shares with his friends , so that they can play together,

I am trying to build a multiplayer game as a Facebook app, So, in this I give one player a link , which he shares with his friends , so that they can play together, FB apps link are of the url type

https://apps.facebook.com/app-name/

Say someone shares a link

https://apps.facebook.com/app-name/?game=key

Now the real problem occurs, how would the app which is开发者_StackOverflow中文版 currently running as an iframe, would access the parent windows game variable?


You have to use the app_data parameter. Have a lookt at these links:

  • Facebook documentation Signed Request
  • Facebook iFrame Tab Applications

So, basically, the app_data parameter will be passed through in the signed_request to your app within the iFrame. For this to work you have to json_encode the parameter. So, in your example case:

http://apps.facebook.com/my-app/?app_data={'game': 'key'}

and finally url encoded:

http://apps.facebook.com/my-app/?app_data=7B%27game%27%3A+%27key%27%7D

to gain access, you have to read out the signed_request (example with PHP):

$app_data = json_decode($signed_request["app_data"]);
$additional = $app_data['additional'];


Basically instead of using a question mark just add it to the URL:

https://apps.facebook.com/app-name/game/key

Just make sure to setup your app to handle things at:

https://yourdomain.com/canvas-url/game/key

I posted a more in-depth answer to this problem over at a duplicate question:

$_GET on facebook iframe app


I just had the same problem, the answer is pretty simple:

https://apps.facebook.com/app-name/?myvalue=12

On Page Apps you can only use "app_data" as parameter, but on Canvas Apps you just use your own parameters and you can get them with $_REQUEST['myvalue'] or $_GET['myvalue']:

array(2) { ["myvalue"]=> string(2) "12" ["signed_request"]=> string(427) "..." } 
0

精彩评论

暂无评论...
验证码 换一张
取 消