开发者

Problem with Facebook apprequests

sometimes I get empty array as result of API call /me/apperquests after sending request via request dialog I'm using PHP library from Facebook's PHP SDK, so auth is ok (and for example /me call is ok).

Can somebody help me, why this is happening? T开发者_如何学编程hank you a lot!


Calling /me/apprequests will return the requests that were sent to you from apps and friends NOT the requests that you sent to others!

apprequests - The user's outstanding requests from an app.


I have suggested a solution to keep track of the requests sent by a user and it's described in depth here.

In short, you handle the response of the apprequests callback which contains the request ids and store them in your DB along with the user's (sender) id.

Code:

<?php
// PATH TO THE FB-PHP-SDK
require_once '../src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'APP_ID',
  'secret' => 'APP_SECRET'
));

$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl();

if ( empty($user) ) {
    echo("<script> top.location.href='" . $loginUrl . "'</script>");
    exit();
}
?>
<!doctype html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<a href="#">Send Application Request</a>

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
          appId   : 'APP_ID',
          status  : true,
          cookie  : true,
          xfbml   : true,
          oauth   : true
        });
    };

    $('a').click(sendRequest);
    function sendRequest() {
        FB.ui({
            method: 'apprequests',
            message: 'Check out this application!',
            title: 'Send your friends an application request',
        },
        function (response) {
            if (response && response.request_ids) {
                var requests = response.request_ids.join(',');
                $.post('handle_requests.php',{uid: <?php echo $user; ?>, request_ids: requests},function(resp) {
                    // do something
                });
            } else {
                alert('canceled');
            }
        });
        return false;
    }

    (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
    }());
</script>
</body>
</html>

Obviously the PHP-SDK is not really needed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜