How to get the direct link to a facebook iFrame url? - facebook

I have a app which url is like:
https://www.facebook.com/Foo/app_123456789
this app is running in a iframe and loading some urls of my server. At the start the user see a page like[1]:
www.foo.com/index.php
but in the app you also get pages like[2]:
https://foo.com/foo1/test/Tab/New/12345-6789
now the question:
is it possible to get a link which start with facebook.com/... and directly lead you to the [2] url?

Yes it is possible. You can add an extra variable to your URL like so:
https://www.facebook.com/Foo/app_123456789?app_data=any_string_here
Facebook will then send whatever inside the app_data variable to your iframe inside the singed_request. So all you have to do is to check for its presence (and value) and redirect the user accordingly.

Related

is it possible to share whole Fb app Canvas page through app?

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?

How to Link FB Share button to URL inside Application?

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.

Facebook fan page app pass string to app_data and retrieve

Hi i have a multiple page facebook fan page app in asp.net c#. how do i set and retrieve that app_data querystring? is this part of the signedrequest or the actual url of the fan page? will there be cross domian issues in getting this in safari and ie?
i can get the signed_request using the following:
if (!string.IsNullOrEmpty(signedRequest))
{
dynamic SignedRequestData;
var DecodedSignedRequest = FacebookWebContext.Current.SignedRequest.Data;
SignedRequestData = DecodedSignedRequest
so basically on the first page i want to get the signed_reqeuest using the above and then append this to the url in app_data querystring. on all other requests i can then get this and use those values to check user status, liked, logged in etc. This way i think it will stop the cross domain cookie issues in safari. anyone agree or disagree with this?
has anyone done this?
cheers
You can set the app_data as:
https://www.facebook.com/{page_id}?sk=app_{app_id}&app_data={"key1":"value1","key2":"value2"}
You can pass multiple values into app_data and it will be returned in the signed_request to your actual page as (POST data).
What you should really do is get the signed_request on first page load from POST, and add it to the URL of your app as ...?signed_request={signed_request_string}. Every page should then pass this around in the URL so you can easily check the like and admin status from any sub-page. You don't need to use app_data for this. And in any case, the data will be lost after the any subsequent click / redirect in your app.

How to set app_data with facebook pagetab dialog url?

I am trying to set app_data to a specific tab page. So a facebook user who clicks the page tab will have the app_data available.
I was trying to add app_data to the pagetab dialog url
I tried the following urls:
www.facebook.com/dialog/pagetab?app_id=290672084311996&redirect_uri=https://apps.facebook.com/artware/?app_data=aa
www.facebook.com/dialog/pagetab?app_id=290672084311996&next=https://apps.facebook.com/artware/?app_data=a
www.facebook.com/dialog/pagetab?app_id=290672084311996&next=https://jbartfb.herokuapp.com/?app_data=a
www.facebook.com/dialog/pagetab?app_id=290672084311996&redirect_uri=https://jbartfb.herokuapp.com/?app_data=a
none of them worked for me.
thanks,
shai
You redirect URIs may not contain query params. However: When you redirect to a canvas app (look like you do) you can always use rewrite rules to pass params. For example:
https://apps.facebook.com/artware/landing/install/param1/param2
Everything after your base URL (https://apps.facebook.com/artware/) is just appended to the url of your canvas app. So if your canvas URL is https://mydomain.com/myapp/ the previously mentioned landing URL would load https://mydomain.com/myapp/landing/install/param1/param2 inside the IFrame. From there you can redirect the user to whatever URL you like, query params and all.

How to like / share URLs inside Facebook that contain get-parameters

We are working on a facebook-app with lots of dynamic pages. As the app is embedded in a tab on a facebook page, the urls contain a get-parameter to address the correct tab/app. We want to implement like- and send-buttons for several pages within our app, but facebook seems to dump all get-parameters from urls within facebook. As the result all like- and send-buttons point to the facebook-page itself instead of the tab.
Does anybody now any workaround? We already tried redirects via an external sefor facebook urls only.rver but facebook seems to evaluate the links on click of the like-/send-button (and seems to follow all sort of redirects).
UPDATE:
Here is an example of a problematic url:
https://www.facebook.com/smartmobil.de?sk=app_171502639574871
UPDATE:
The problem seems to be independant of url get-parameters. It seems that the like-button does not work with any url starting with www.facebook.com
When used in a like-button everything behind the ? will be dumped. This seems to happen for facebook urls only.
Best workaround so far is to point your like buttons at external (non-facebook canvas) urls.
To make this work, you need to do some conditional redirecting to get the user back into your canvas URL. You can either use a client side javascript redirect:
<script>
window.location = 'http://apps.facebook.com/yourcanvasname/foo/bar';
</script>
Or you can do a server side redirect based on the useragent string. Basically, if the useragent contains 'facebookexternalhit' then render a basic HTML page containing OG tags, if not, redirect to the canvas URL.
Doing this means the Facebook sharescraper/linter won't follow any redirects back to the canvas URL, but any user that arrives at your URL will get back to Canvas.
i'm too searching for a solution to control the custom page tab's content through a get parameter (app_data). I still don't have a solution but here at least the reason why all www.facebook.com links are srtiped out of get params. Here at bottom the developer explains why.
Unfortunately I don't think what you are trying to do is possible. Posting a like programmatically requires you to specify a Facebook content ID or alias. This won't work for you because tabs to not seem to have an exposed content ID of their own, and instead use the Page's content ID with an additional parameter which you can't use with the graph.
Liking external links and other content that does not have an ID programmatically is prohibited. With an external URL, the first like of an unrecognised URL creates a new Facebook page for those likes to be represented on (which is the issue I've given up trying to fight), but presumably the presence of your Page's content ID alias (www.facebook.com/smartmobil.de) in the url is making Facebook choose you page rather than creating a new one.
The only suggestion I can think of this late at night is to target an external URL that performs a redirect via Javascript, rather than on the server, but Facebook may be wise to that too and I'm afraid I'm going to bed rather than testing it :)