0

I created a Facebook App (Page Tab). This App can be added to Fanpages.
In this App, I make a call with Javascript to get the right JSON Data for my App.

The data is specific to the FB-Site where my App was been added.
I.e. when Coca-Cola adds my App to their Fan Page, I need to know that is coca cola - to get the right data.

Now, my Idea is when creating the Page Tab, save the ID from the Page. And when making a call to get the data in the page tab sending the Fanpage ID as a parameter.

I hope it is reasonably clear what I mean.

My Question is, how got access to ID of the Page? Best with Javascript. Or is this not possible?

I would appreciate any tip!

chris
  • 4,827
  • 6
  • 35
  • 53

1 Answers1

2

This would be very easy with the PHP SDK. A signed_request parameter will get passed on to your iframe, and the PHP SDK offers a function called getSignedRequest() to parse it:

https://developers.facebook.com/docs/reference/php/facebook-getSignedRequest/

For example:

$sr = $fb->getSignedRequest();
echo $sr['page']['id'];

With JavaScript it would be a lot more complicated. You could try to get the signed_request parameter like this: How to retrieve GET parameters from javascript? - But you would have to deal with the parameter on your own. Here´s how to parse the parameter on your own with PHP: https://developers.facebook.com/docs/facebook-login/using-login-with-games

No Facebook SDK needed in that case, btw. And it should also work with PHP <5.4.

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Thanks you for suppport! This works great for me. Do you got an idea how found also the page name? :-/ – chris May 21 '14 at 12:36
  • 1
    sure, that would be possible with curl or file_get_contents with a request to this endpoint: https://graph.facebook.com/[page-id] - just try it directly in the browser, it returns some data of the page including the "name" field. – andyrandy May 21 '14 at 14:04
  • 1
    of course you can also use the php sdk: $result = $fb->api('/[page-id]'); – andyrandy May 21 '14 at 14:05