First off, thanks for this great app.

I've created an app that works in canvas, but I wanted to get it working in a Page Tab too.

I noticed that when using fb_require_authorization(); it redirects (after auth) to the app as a website. Giving this a $redirection parameter of the absolute path to the Facebook page tab throws an error because it wants the domain to be the same as the app. So I just put some code in my .tpl.php that checks if $_GET['code'] exists (the variable FB passes after auth) and if so, to redirect to the Page Tab URL.

This worked fine, however if I click any link within the app it sends me to the website direct, as if there is no URL rewriting like what takes place in the canvas app. I've got all the options checked in admin/structure/fb/fb_tab. I noticed it says there redirect to canvas - there is no option to stay within the Page Tab iFrame?

The app is http://apps.facebook.com/bgs-photocomp

Thanks for any help.

Comments

Dave Cohen’s picture

Category: bug » support

The links that appear on canvas pages and tabs are affected by something I call "processing" its different from what drupal calls "URL rewriting" although the two are related.

The closest there is to an option to stay on the page tab is to uncheck "Enable processing on iframe tabs" on admin/structure/fb/fb_tab. however, I don't recommend that for most sites. Its very easy to get links on the page that wont work as expected, for example an absolute link to another site.

When the user visits a canvas page or tab, facebook includes a "signed request" in the HTTP request, giving drupal some context. Once you follow one of these unprocessed links, that signed request is gone. In some cases this is fine, but in others its not, and just testing all the permutations of browsers, third-party cookie options, and so on... you'll pull your hair out at some point.

So, I recommend taking the user away from a page tab as soon as they click any link. Check out facebook's own page tabs (i.e. photos), you'll see all the links take you away from the tab. (If I'm wrong about that, please let me know.)

Red Rover’s picture

The Facebook photo's is a perfect example, and I didn't actually realise that was happening - which I guess proves that the experience is seamless for a user. I have seen some apps contain it in the tab, but I think you're quite right.

Having said that, my links are not being 'processed' as you'd call it - as in, they lead to the root website instead of the canvas page. Is this intended also?

Thank you very much for your prompt reply!

Dave Cohen’s picture

Under admin/structure/fb/fb_tab, make sure all boxes are checked.

Make sure you have fb_url_rewrite.inc and fb_settings.inc included in your settings.php.

Are the links created by Drupal's menu system or l() or url() functions. If they're hard-coded, that's the problem.

If still a problem, enable fb_devel.module and add it's block to your page tab. That will tell you whether modules/fb actually believes it is serving up a page tab. If it does believe that, there may be a bug.

Red Rover’s picture

All boxes are checked, and I have both .inc files in my settings.php files also.

The links that aren't being rewritten are being generated by Views. I tested with a menu, and the menu works (leads to Canvas app). A bug with Views? Because the Views URLs are correctly altered in the Canvas app, just not the page tab.

Instead however, as per your suggestion above, would it be better to have the oAuth destination page as the canvas page? Because the canvas page is working, that means I could essentially have the Tab appear on the fan page, it asks for permission, and then redirects to the canvas app directly, instead of waiting for them to click on content first. Would this work? When attempting to set the destination argument, fb throws the error that the URL isn't a valid one (not using the apps domain).

Edit: the other thing is if the user hasn't yet authorised the app and visits through the Page Tab, the destination URL is the app website, again not directing to the tab (or canvas).

Edit 2: I forgot to mention, I'm styling the view, but I'm using your function to set the URLs - that could be the reason it's not functioning for the Tab Page? Code is below:

<?php $photoUrl = url('photo/', array('absolute' => TRUE, 'fb_canvas' => fb_is_canvas())); ?>
<div class="photo-box">	
	<div class="photo-image"><a target="_top" href='<?php print $photoUrl . $fields['title']->raw; ?>'><div class="imgwrap"><?php print $fields['field_photo']->content; ?></div></a>
	<div class="photo-rating"><?php print $fields['field_rating']->content; ?></div>
	</div>  
</div>
Dave Cohen’s picture

$photoUrl = url('photo/', array('absolute' => TRUE, 'fb_canvas' => fb_is_canvas()));

That code, on a page tab, will link the user to the website, because you're explicitly setting fb_canvas to FALSE. Try 'fb_canvas' => TRUE, or leave out the array() to see what the configured behavoir is (same as menu links). Those options override the configuration.