Search code examples
facebookapifbjs

Set a custom redirect after user accept permissions - Facebook Application


I try to build an app and i want to ask for permissions first, so the code below do just these but when it redirects, is transfer me in the domain i host the application.

Is it possible to set a custom redirect?

thanks a lot!

<html>
    <head>
        <title>Client Flow Example</title>
    </head>
    <body>
        <script>

        var appId = "YOUR_APP_ID";

        if(window.location.hash.length == 0)
        {
            url = "https://www.facebook.com/dialog/oauth?client_id=" + 
                     appId  + "&redirect_uri=" + window.location +
                     "&response_type=token";
            window.open(url);

        } else {
            accessToken = window.location.hash.substring(1);
            graphUrl = "https://graph.facebook.com/me?" + accessToken +
                        "&callback=displayUser"

            //use JSON-P to call the graph
            var script = document.createElement("script");
            script.src = graphUrl;
            document.body.appendChild(script);  
        }

        function displayUser(user) {
            userName.innerText = user.name;
        }
        </script>
        <p id="userName"></p>
    </body>
</html>

Solution

  • I guess you only have to change this part :

    "&redirect_uri=" + window.location +
    

    To

    "&redirect_uri=THE_URL_YOU_WANT" +
    

    But I'm not sure I understand your question correctly ? Could you clarify ?