开发者

"Request Dialog" requestCallback when clicking Cancel or Close button

开发者 https://www.devze.com 2023-04-12 19:32 出处:网络
I am new into Facebook application development and also newbie about JavaScript and PHP programming. I currently developing a Facebook application but currently stuck with Request Dialog window.

I am new into Facebook application development and also newbie about JavaScript and PHP programming.

I currently developing a Facebook application but currently stuck with Request Dialog window.

When the Request Dialog appears, I choose friends I want and then click "Send Requests", the requestCallback(response) are executed and friends who getting requests are notified as expected. But, If I click "Cancel" or the blue-colored close button, the requestCallback(response) is also executed but selected friends are not getting notified about the request.

Here is my code:

function requestCallback(response)
{
    //console.log(response);
    location.href='step2.php';
}

So, whether I click "Cancel" or close button,开发者_StackOverflow社区 the script above are still executed (moving to page step2.php I specify.)

What I want is when the user clicking cancel button or close modal window button, the page stay at the same page.

Anyone know how to solve this problem?

Thanks!


You can just check what's inside the Facebook response object, because it won't be the same if requests have been sent or not !

Something like :

function requestCallback(response)
{
    if(response && response.request_ids) {
         // Here, requests have been sent, facebook gives you the ids of all requests
         //console.log(response);
         location.href='step2.php';
    } else {
         // No requests sent, you can do what you want (like...nothing, and stay on the page).
    }
}

Or if you are using the new structure (Request 2.0 Efficient):

function requestCallback(response)
{
    if(response && response.request) {
         // Here, requests have been sent, facebook gives you the request and the array of recipients
         //console.log(response);
         location.href='step2.php';
    } else {
         // No requests sent, you can do what you want (like...nothing, and stay on the page).
    }
}

Look at the structure of the response object to make your condition. The callback is fired even when you hit close in order to have the possibility to notice when your user quits the dialog. It's up to you to verify if he sent requests, and act like you want ! :)

Also, something important : Facebook updated their request system a few weeks ago, making available "Requests 2.0" in your apps settings. It's turned off by default, but if you activate it, the structure of the response object when sending requests to people will change. So you'd have to update your condition in the callback !

Everything is explained here : http://developers.facebook.com/blog/post/569/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号