Deeplinking using GWT History Token within a Facebook iFrame Canvas - facebook

I would like to deep link directly to a GWT app page within a Facebook iFrame Canvas.
The first part is simple using GWT's History token with URLs like:
http://www.example.com/MyApp/#page1
which would open page1 within my app.
Facebook Apps use an application url like:
http://apps.facebook.com/myAppName
which frames my Canvas Callback URL
http://www.example.com/MyApp/
Is there a way to specify a canvas callback url (or bookmark url) which will take the user to a specific page rather than the index page?
Why? you may ask. Besides all the benefits of deep links...
I want the "Go To Application" url to take users to an index page w/ marketing material (the canvas callback url)
I want the "Bookmark URL" to take (likely returning) users to a login page and bypass downloading the marketing content (and that huge SWF file).

This may seem to be a hack but here it goes.
Facebook allows the application to tack on parameters to the url ?x=123
So I'm checking the window location to see if it contains my special 'page' parameter and loading that page. Below is my solution given that I'm using GWT + gwt-presenter's PlaceManager class.
The application deep url ends up being http://apps.facebook.com/myAppName?page=page1
EventBus eventBus = injector.getEventBus();
// Load PlaceManager so it can start listening
PlaceManager placeManager = injector.getPlaceManager();
String currentPlace = History.getToken();
String place = Window.Location.getParameter( "page" );
if (place != null && !place.isEmpty()) {
// send user to the place on the URL line
eventBus.fireEvent( new PlaceRequestEvent( new PlaceRequest( new Place (place) ) ));
} else if ("".equals(currentPlace)) {
// Nothing in URL, load default GWTpage
eventBus.fireEvent( new PlaceRequestEvent(new PlaceRequest( IndexPresenter.PLACE)));
} else {
// fire a body to the Place Manager to activate the requsted Place
placeManager.fireCurrentPlace();
}

Related

How to stop redirected URL from being masked?

I have a doGet function in my google apps script (attached to a google doc) which is published as a web app and I want the user to be redirected to another web page. Importantly, I want the URL of the page they are redirected to be displayed in the address bar, and the title of the page they are redirected to be the title of the tab (in Chrome).
I've tried using a meta refresh tag, and setting the window.location.href. Both of these redirect correctly but they show the URL of the address app in the address bar, not the URL of the page the user is redirected to.
The below script, attached to a Google Doc, illustrates the problem.
function doGet(request) {
var drive = DriveApp;
var docs = DocumentApp;
var Id = docs.getActiveDocument().getId();
var document = docs.openById(drive.getFileById(Id).makeCopy().getId());
document.setName("Test doc 2");
var URL = document.getUrl();
return HtmlService.createHtmlOutput('<meta http-equiv="refresh" content="0; url=' + URL + '" />')
}
Publishing the script as a web app and then visiting the URL redirects you to the newly created document, but it is the URL of the script that displays in the address bar.
See this Google Doc for an example: https://docs.google.com/document/d/1HpBkNGGGjKj3W6QXThtGdniSO_UTANo8LcqmgZowdTQ/edit
Since your html is loaded in a inner iframe, You should use
window.top.location = url
to load in the top frame.

Is there a way to conditionally block a referer in Google Tag Manager?

We have an issue with GA where conversion sources are being lost after a user clicks on a link to our site, goes to the site, and then logs in using Facebook.
My understanding from GTM tips - implement referral exclusions is that our site sees the document.referrer as coming from Facebook and starts a new session, losing the original referrer. If we know the landing page on our site the user sees after logging into Facebook, is it possible to add code to exclude the FB referrer only for that page? I.e, on that one page we have something like (from the linked article):
function() {
var referrals = [
'facebook.com'
];
var hname = new RegExp('https?://([^/:]+)').exec({{Referrer}});
if (hname) {
for (var i = referrals.length; i--;) {
if (new RegExp(referrals[i] + '$').test(hname[1])) {
return null;
}
}
}
return {{Referrer}};
}
We can't simply add facebook.com to the GA exclusion list, as we have campaigns running on Facebook as well, so we'd still need visibility to organic traffic coming from Facebook.
You can copy GA tag and modify the copy with this code. Then fire that copy only on pages where you need to block referrer and block original GA tag on same pages.
If you don't want to have multiple GA pageview tags then use Lookup Table variable based on page paths. For some pages this variable should return your code as a Custom JavaScript variable and a default value should be {{Referrer}}.

Android Facebook C# login not loading internally

I'm trying to follow Prabir's blog post about Facebook authentication and adapt it in an Xamarin Android-based application. I have a login page that has the following code defined to generate the URL;
private Uri GenerateLoginUrl(string appId, string extendedPermissions)
{
var parameters = new Dictionary<String, Object> ();
parameters.Add("client_id", appId);
parameters.Add ("redirect_uri", "https://www.facebook.com/connect/login_success.html");
parameters.Add("response_type", "token");
parameters.Add("display", "popup");
if (!string.IsNullOrWhiteSpace(extendedPermissions))
parameters.Add("scope", extendedPermissions);
var fb = new FacebookClient();
return fb.GetLoginUrl(parameters);
}
On create of the view, I call this method and assign it to a WebView element:
var browser = this.FindViewById<WebView>(Resource.Id.LoginView);
Uri url = GenerateLoginUrl("<app id>", "");
browser.LoadUrl (url.ToString ());
In the view, I have the following defined:
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LoginView" />
When LoadUrl is called, it prompts to open a browser externally (open in Chrome|Firefox|Opera options), not login through the WebView control defined in my view tied to the LoginActivity. I don't know what is going on here, and why this is happening. How can I display the request within the webview control, within the application itself and not externally?
So it sounds like the system URL handling is getting in your way. What you need to do is set a WebViewClient on your WebView. This will allow you to return true from shouldOverrideUrlLoading (which I believe is the default) which will then allow the requested resource to be loaded by your application.
See the relevant documentation here in WebViewClient, shouldOverrideUrlLoading specifically. But the takeaway is
If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url.
Which in the case of an http-based URI, will most certainly be the system browser.

Facebook share to refer back traffic to the iframe page tab

SO here's what I am after. I have a FB page tab that runs the content of the site https://site.com/
I set up a FB share link to share a page aboutus.html. When I share it FB allows me to share this URL https://site.com/aboutus.html, but how can i send the traffic directly to the iFrame on the page tab? For example https://www.facebook.com/fan_page/app_331267943480920398/whatever_aboutus.html
I know it is possible because I saw it one day - cant remember now where.
Thanks.
You can't pass in filenames this way, that's only supported on Canvas Apps.
The best workaround to replicate this is using the app_data parameter. Basically, have your landing page (as defined in your app settings), be some kind of server side script which listens to the Signed Request, specifically the app_data parameter. Then you have that script load content based on the contents of that.
So as an example, let's imagine I want to load http://mybasedomain.com/foo.php or http://mybasedomain.com/bar.php. I direct users to https://www.facebook.com/PAGENAME/app_APPID?app_data=foo or https://www.facebook.com/PAGENAME/app_APPID?app_data=bar, then on my landing page, I have a simple if/else statement to parse that and render the relevant content -
<?php
// Assumes you have this parse_signed_request function - https://gist.github.com/872837
// And a $config array, which contains your app_secret
$signed_request = parse_signed_request($_REQUEST['signed_request'], $config['AppSecret']);
if ($signed_request['app_data'] === 'foo') {
include('foo.html');
} else if ($signed_request['app_data'] === 'bar') {
include('bar.html');
} else {
include('index.html');
}

Getting Actual Facebook and Twitter Profile Image URLS for Flex Security Policy

I'm trying to display the profile images from both facebook and twitter. For facebook, the URLs I'm receiving are something like this (not actual urls):
http://graph.facebook.com/965412145/picture
Which is then redirected to the 'actual' url like this:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/370471_9631690_1796253478_r.jpg
I'm also doing this with twitter, with the same issue (redirected url).
So, when I load the image, it loads fine. But when I close the container that the image is in, then I get the security sandbox violation.
I can get this all to work if I add the URL from the 'actual' image url like this:
request = new URLRequest("http://profile.ak.fbcdn.net");
loader = new Loader();
context = new LoaderContext();
context.checkPolicyFile = true;
loader.load(request, context);
However, at run time, I do not actually know what the 'actual' image url is, so I can't hard-code that domain in (nor do I want to).
Is there a way to get the actual url (from within flex) of the image so that I can add the correct domain to the loadercontext?
Any ideas are appreciated!
If I understand correctly, your problem is that you're trying to load an image from a URL that redirects to another source. You need to know what the redirected URL is, so you can load a policy file that allow manipulation of image bytes.
If I've understood correctly, you need to detect the redirected URL by listening for the COMPLETE event (or an error event), then reference the LoaderInfo.url property. This property will reflect the end URL in the event of redirects. For example, you would have code like this in the listener:
var ldr:LoaderInfo = event.target as LoaderInfo;
var url:String;
try
{
url = ldr.url;
// Split off URL base, load policy file, etc here
}
catch (e:Error)
{
// Unable to detect final URL due to error.
}