Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

facebook redirect app from canvas page to fan page

im building facebook app as a iframe app in fan page. My problem at the moment is next: i added facebook request dialog (http://developers.facebook.com/docs/reference/dialogs/requests), and everything goes well except for one thing: when a user gets notification, the links goes to canvas page, not to fan page (where i would like to go...)

Since i cant convince facebook to add some funcionality (that would be great), im looking for a way to automaticly redirect from app canvas page to fan page, where this app is added as iframe tab.

I hope somebody understands what i want to do... :)

thanks, Peter

like image 212
Peter Avatar asked Apr 19 '11 10:04

Peter


3 Answers

I also wanted to make sure that users view my Facebook app via a Facebook Page Tab (rather than via the Facebook App page or by directly viewing the actual site itself). I have managed to achieve it with this Javascript in a <script> tag in the head of my document (tested Mac/PC FF,Chrome,Opera,IE6-8,Safari).

<script type="text/javascript">
  function NotInFacebookFrame() {
    return top === self;
  }
  function ReferrerIsFacebookApp() {
    if(document.referrer) {
      return document.referrer.indexOf("apps.facebook.com") != -1;
    }
    return false;
  }
  if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
    top.location.replace("http://permalink-to-my-facebook-page-tab");
  }
</script>
like image 158
stephen Avatar answered Nov 03 '22 13:11

stephen


If I understand you correctly, you can do this:

top.location.href='http://www.facebook.com/YOUR_PAGE_NAME?sk=app_YOUR_APP_ID'

or you can use a header to redirect to that url. This will redirect to the application's tab on your fan page.

like image 45
DannyKK Avatar answered Nov 03 '22 11:11

DannyKK


My application is quite dynamic and I never know which page it's added to. So when I used URL 'http://www.facebook.com/YOUR_PAGE_NAME?sk=app_YOUR_APP_ID' it only redirected me to page, but not to application tab. What I do is:

1) I get page id from signed_request (the encrypted in base64url parameter that your app gets once someone comes to the page, so you have to decrypt it and pick id value from JSON page object)

2) Then I get page data from https://graph.facebook.com/PAGE_ID_YOUR_GET. You get JSON object with some page data in response in JSON format.

3) Only after point 2 I get 'link' value of page from response. It's like http://www.facebook.com/pages/Some-Page-Name

4) And finally I add '?sk=app_YOUR_APP_ID' to page link.

Maybe that's too complicated, but that's the only way it worked for me the way I expected (redirecting exactly to page application tab).

like image 2
Anton M Avatar answered Nov 03 '22 13:11

Anton M