I have an iframe tab which holds php page with various links inside (like "News", "Photos" etc.). Is it possible to generate a facebook link which leads directly to certain link inside the iframe? By facebook link I mean link that will keep you on facebook, open your iframe tab and view certain page on that iframe. The thing is that all I can do now is to link only to my iframe tab which has address like http://www.facebook.com/mypage/app_someid. Then I will land on my default page tab url. But I want to land on different one. Any tips on this one?
Passing an app_data parameter to the tab URL is passed back to your application as part of the signed_request parameter in FB's post call to include your content. Use that parameter after de-signing it to then decide what to show and what not to.
Your URLs will become like:
http://www.facebook.com/mypage/app_someid?app_data=showViewX
http://www.facebook.com/mypage/app_someid?app_data=showViewY
and then in your code:
// Get Signed Request
$app_data = $signed_request['app_data'];
if($app_data === "showViewX") {
// Show one view
} else {
// show others..
}
Currently, the app_data param is not sent if the user just liked the page when he lands on it with an app_data param. The bug on FB has been filed at https://developers.facebook.com/bugs/172963266154996 and we are all hoping for an early resolution.
Related
I'm working on a photo contest fb app to run in a fan page tab. the user should be able to share the photo in order for others to vote for them.
supposing image link in iframe is http://example.com/image.php?id=1 for particular photo, pressing share will share this link through iframe. which leads up to the host app itself.
what I need is sharing the whole fb app tab page url with http://example.com/image.php?id=1 open in its Iframe.
is that possible in any way?
thanks for help.
So to give the “alternative” to #Lix’ answer, which focuses on canvas apps, here the analog way for page tab apps:
For some reason Facebook decided to do things differently for page tab apps – different than with canvas apps, you can not pass just any GET parameters to your app by appending them to the facebook.com address of your app, but you have to use the app_data parameter for that.
You call/link to your app in the form https://www.facebook.com/YourPage?v=app_1234567890&app_data=foo – and whatever you put as value for the parameter app_data, you will find in the signed_request parameter that Facebook POSTs to your app on initial(!) load into the iframe.
So you parse the signed_request (or let f.e. the PHP SDK do that for you), and then you find the app_data value in there. If you want to pass more than one single value, you can f.e. also put JSON-encoded data there – then you have to decode that again after you read the app_data value from the signed request.
The docs just shortly mention the app_data parameter, but the principle itself is quite simple.
Now, when it comes to sharing those links, I found that when you use an address in the above form, Facebook tends to cut the parameters from the URL, and treat the whole link as just a link to your Facebook page – it shows the page’s picture and description, and does not even pass your page tab app along, let alone the app_data parameter.
I found the most reliable way around this is not to link to your page tab on Facebook directly, but instead to a URL of your own app. When the scraper visits it, you deliver the relevant OG information. And when it’s a real user visiting, you redirect them to your page tab app, passing the data you need via the app_data parameter as described above. Redirecting can either be done server-side (info on how to detect the scraper server-side via its User-Agent header), or client-side via JavaScript (which the scraper does not “speak”).
Sure it is. All you have to do is be able to extract the information from your application canvas URL. If your canvas URL is something like this:
https://apps.facebook.com/ImadBakir
Then you could place some more info in there, like this:
https://apps.facebook.com/ImadBakir?photo_id=123
Users will share that link and now in your application, you can parse that photo_id parameter and make the needed HTML changes to display the correct image inside your iframe as the page and application loads.
With regard to parsing the the URL parameters, assuming you'll be doing it with JavaScript, you can read more about it in this post:
How can I get query string values in JavaScript?
We are creating a canvas app and would like to add directly to my fanpage.
There are 2 ways that I'm not sure about how to take the user to the app's fanpage.
First would be to create a tab and add it in the fanpage.
On this tab would have some text and a call-to-action to redirect to app canvas.
Would create a second tab and add it in the fanpage only with a redirect to take the user directly to the fanpage of the app.
Is there any documentation specific to this practice or some restriction to redirect the tab?
To see if your app was loaded inside a page tab, parse the signed_request server-side and look if there is a page-id set.
If so, answer that request with a minimal HTML document containing not much more than a piece of JavaScript code to redirect inside the top window instance, like this:
top.location.href = "https://apps.facebook.com/yourappsnamespace";
There should be no restrictions on that – Facebook is only worried about automatically redirecting users away from Facebook (to outside domains), but since you are redirecting to a canvas app, they stay on their site.
The docs clearly state:
We do not accept Canvas pages that redirect to Page Tabs, or vice
versa.
I have multiple share buttons inside my application. When i click them it shares the link of the iframe for example:
www.mypage.com/?whatever=whatelse
But i need to share this link with the facebook page "around" so the link is in he facebook iframe inside my apllication:
www.facebook.com/mypage/app_123456789/?????????????????
Is it possible to set some parameters to deeplink inside my application for sharing ?
Right now i just share the index page of my application without any parameters or a specific url inside.
You'd have to use the signed_request variable to store the the page you wanted to share. From what I remember there is an app_data field in this that allows you to store custom values - https://developers.facebook.com/docs/authentication/signed_request/
You'd then have to extract the custom variable from the signed_request->app_data when the page is requested to determine which content to load. You could then obviously share the link to the fb page with the signed_request tacked on. It is still requesting just one page, but kinda simulates deep-linking.
I can send requests to friends using "Multi Friend Request Selector" inside my Page Tab App, which link looks like :
https://www.facebook.com/<my_page_name>/app_<my_app_id>
My friend receives my request, and click "Accept". It forwards to the real link of the Facebook App, which is :
https://apps.facebook.com/<my_app_name>/?fb_source=request&request_ids=<an_request_id>
which is not inside a Page Tab anymore. How can I forward to user to the 1st link instead of the 2nd while the request_ids have to be kept? Do I just make a header('Location: url'); forwarding?
p.s. Timeline is already in use.
Yes you have to forward to your page url, because requests always redirect to the canvas url.
To pass the request ids you can use the app_data field. So instead of redirecting to https://www.facebook.com/<my_page_name>/app_<my_app_id> you redirect to https://www.facebook.com/<my_page_name>/app_<my_app_id>?app_data=requestids. Here requestids are the actual values(the comma separated list that the canvas gets).
app_data is available to your page tab app as part of the signed_request it receives.
From docs:
In addition, your app will also receive a string parameter called app_data as part of signed_request if an app_data parameter was set in the original query string in the URL your tab is loaded on. For the Shop Now link above, that could look like this: "https://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here". You can use that to customize the content you render if you control the generation of the link.
The Facebook API docs say the parameter, "app_data," should be used to customize tabs within a Facebook Fan Page.
However, when users add our tab to their page, the "app_data" param gets lost every time, meaning the tabs aren't customized per Fan Page as they should be.
For instance, we want this page to get rendered for one client: http://www.facebook.com/apps/application.php?id=198939416792674&sk=app_198939416792674&app_data=15
After the client adds this URL as a tab to his Fan Page, though, the tab URL loses the "app_data" parameter. The page rendered no longer reflects the data specific to this client.
We need the tabs to contain a parameter specific to each Fan Page. We thought "app_data" was the right approach.
Any clues what we're doing wrong?
The best way to do what you trying to achieve is to customise the content based on the page['id'] that is passed to you via a signed request.