Wazan
Wazan

Reputation: 539

How to work with facebook setUrlHandler?

Im using an App("http://apps.facebook.com/greetingz") and this is the ajax part im using, I can send a request and also receiver receiving a notification but when receiver click on the notification its goes to directly canvas page "apps.facebook.com/greetingz" , actually i wanna show a different page.. please help on this !!

    <?php 
         $app_id = "127736900693315";

         $canvas_page = "http://apps.facebook.com/greetingz";

         $message = $_POST['varx'];


         $requests_url = "https://www.facebook.com/dialog/apprequests?app_id=" 
                . $app_id . "&redirect_uri=" . urlencode($canvas_page)
                . "&message=" . $message;

         if (empty($_REQUEST["request_ids"])) {
            echo("<script> top.location.href='" . $requests_url . "'</script>");


         } else {
           // echo "Request Ids: ";
            //print_r($_REQUEST["request_ids"]);
            echo $message;
         }
?>

how can i use below code to this App

 function onUrl(data) {
 if (data.path.indexOf("games.achieves") != -1) {
     console.log('I will process some achievement now.');
 } else if (data.path.indexOf("request_ids") != -1) {
     console.log('I will process some request now.');
 } else {
     // default behaviour
     window.location = data.path;
 }

}

FB.Canvas.setUrlHandler(onUrl);

Upvotes: 0

Views: 470

Answers (1)

deadrunk
deadrunk

Reputation: 14155

You have to set the handler function with some delay after initialization of the FB api.

FB.init(params);
setTimeout(function() { FB.Canvas.setUrlHandler(onUrl) }, 5000);

Using this way I got this feature working.

Upvotes: 2

Related Questions