Redirección de Facebook después de iniciar sesión
Frecuentes
Visto 2,554 veces
2
I have read a number of questions and answers, including esta on StackOverflow and none works. My question to all responses I have seen are 'does it work in Safari?'.
I am trying to get this to work with Safari. It works on Chrome and Firefox fine. But in Safari the login screen just freezes and I get the "Unsafe JavaScript attempt to access frame with URL" log message.
I have a canvas app. I want to log the user in and redirect them to a page once they have logged in. I am trying to redirect directly after login. I have tried
pólipo
window.top.location
to a facebook url (with some data passed to a signed request as the all_data argument)pólipo
window.location
to a URL with the same domain as my app.suscribiéndose al
auth.login
event and putting the redirect thereputting the redirect in the callback to login
None of these works for Safari. I'm starting to think that there's no way to do it.
function doSomething()
{
FB.login(
function(loginResponse)
{
if (loginResponse.authResponse)
{
window.top.location = "my url"
}
},
{
scope:"some,scope"
}
);
}
}
In response to Nitzan Tomer, here is the equivalent code which doesn't work with Safari but does work with others:
function myThing()
{
FB.login(function(loginResponse)
{
if (loginResponse.authResponse)
{
FB.api('/me', function(response)
{
window.location = "http://my_app.com?x=" + response.xyz;
});
}
},
{
scope:"scopes"
}
);
}
2 Respuestas
0
This is not much of a solution to your problem, but more of a "workaround", though it still uses window.top.location
but not from a callback so maybe it will work (I'm just not sure where the callback is executed, since it's the fb sdk that executes it, maybe they call it from the fb iframe inside your iframe).
Instead of using client side authentication, you can use the flujo del lado del servidor.
The entire process is happening on the top window, since it starts by you redirecting the user to the oauth dialog using window.top.location
.
When the process ends facebook redirects the user to your redirect_uri, and there you can simply redirect the user where ever you want.
I hope this will help. Also, you should be aware that in the Políticas de la plataforma de Facebook afirma:
13 . The primary purpose of your Canvas or Page Tab app on Facebook must not be to simply redirect users out of the Facebook experience and onto an external site.
contestado el 22 de mayo de 12 a las 17:05
0
It turns out the problem was occurring slightly earlier in the login process and the callback never got called. I did set a breakpoint in the callback (which wasn't called) but I thought the breakpoint might not work for some reason (perhaps because it was being executed in the context of another window).
Anyway, the problem was that the channel file (which the docs seem to suggest are optional) wasn't working properly, and this caused a problem with Safari but not with other browsers.
contestado el 23 de mayo de 12 a las 11:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas facebook facebook-canvas facebook-javascript-sdk or haz tu propia pregunta.
Thanks I'll look into it. For clarification, I am just trying to move between screens in my canvas app, not going to another site. - Joe
So why do you want to use
window.top.location
? Solo usawindow.location
to change the url of your iframe and not the main window. - nitzan tomerThat's the whole point. That method works for Chrome and FF, but it just doesn't work for Safari. - Joe
Thanks for your help, I've updated my question with code about as close as possible to my real code. - Joe
The error that you posted ("Unsafe JavaScript attempt to access frame with URL") usually does not block the execution, but it is just logged. Maybe there's another error in safari? First of all it should be
window.location.href = ...
y no solowindow.location
, also maybe add a try/catch at the beginning of the function to check. - nitzan tomer