FB.ui中的回复({method:'apprequests'无法正常工作

时间:2011-11-07 17:21:13

标签: facebook response

我总是得到

  

无法发送邀请。请尝试下一步

本应用程序中的

消息。我找不到任何错误。为什么这段代码不起作用?它应该成功发送请求和警报成功消息。

<?php
    require_once '/facebook-php-sdk-1f4b893/src/facebook.php';
    $facebook = new Facebook(array(
    'appId'  => 'XXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXX'
));

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

if ( empty($user) ) {
    echo("<script> top.location.href='" . $loginUrl . "'</script>");
    exit();
}
?>
<!DOCTYPE html>
<html xmlns:fb="https://www.facebook.com/2008/fbml">
<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   : 'XXXXX',
          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) {
           alert('Invitation has been sent');
        } else {
            alert('Cannot send invitation. Please try next');
        }
    });
    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>

0 个答案:

没有答案