Después de pasar toda una jornada de trabajo sobre este problema, tengo una muy buena solución que me gustaría compartir. En lugar de usar el SDK con FB.ui(), descubrí que puedo evitarlo completamente abriendo manualmente mi ventana emergente al https://www.facebook.com/dialog/feed. Al hacerlo de esta manera, redirect_uri funciona como se esperaba, y puede redirigir a un archivo HTML que cierra la ventana emergente. Si el usuario hace clic en compartir o cancelar, la ventana emergente se cerrará como se esperaba.
no creo que hay ningún compromiso con este código y, en todo caso, es mucho más fácil de usar que el SDK real.
código Javascript Mi (que se puede guardar como FacebookFeedDialog.js) tiene el siguiente aspecto:
/* by Steven Yang, Feb 2015, originally for www.mathscore.com. This code is free for anybody to use as long as you include this comment. */
function FacebookFeedDialog(appID, linkTarget, redirectTarget) {
this.mParams = {
app_id: appID,
link: linkTarget,
redirect_uri: redirectTarget,
display: "popup"
}
};
/* Common params include:
name - the title that appears in bold font
description - the text that appears below the title
picture - complete URL path to the image on the left of the dialog
caption - replaces the link text
*/
FacebookFeedDialog.prototype.addParam = function(key, value) {
this.mParams[key] = value;
};
FacebookFeedDialog.prototype.open = function() {
var url = 'https://www.facebook.com/dialog/feed?' + encodeCGIArgs(this.mParams);
popup(url, 'feedDialog', 700, 400);
};
/* Takes a param object like this:
{ arg1: "value1", arg2: "value2" }
and converts into CGI args like this:
arg1=value1&arg2=value2
The values and args will be properly URI encoded
*/
function encodeCGIArgs(paramObject) {
var result = '';
for (var key in paramObject) {
if (result)
result += '&';
result += encodeURIComponent(key) + '=' + encodeURIComponent(paramObject[key]);
}
return result;
}
function popup(mylink,windowname,width,height) {
if (!window.focus) return;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
if (!windowname)
windowname='mywindow';
if (!width)
width=600;
if (!height)
height=350;
window.open(href, windowname, 'resizable=yes,width='+width+',height='+height+',scrollbars=yes');
}
Aquí hay un ejemplo de archivo HTML que utiliza el código Javascript arriba:
<HTML>
<BODY>
<SCRIPT type="text/javascript" src="FacebookFeedDialog.js"></SCRIPT>
<SCRIPT>
var dialog = new FacebookFeedDialog(yourAppIDGoesHere,yourDestinationURLGoesHere,yourCloseWindowURLGoesHere);
dialog.addParam('name','This is my title');
dialog.addParam('description','This is the description');
dialog.addParam('picture',yourImageURLGoesHere);
dialog.addParam('caption','This is the caption');
</SCRIPT>
<A href="javascript:dialog.open()">Open facebook dialog</A>
</BODY>
</HTML>
Su CloseWindow html el archivo puede verse así:
<SCRIPT>
window.close();
</SCRIPT>
entonces, ¿no puedes evitar ser redireccionado, realmente? – geekazoid