我总是得到
本应用程序中的无法发送邀请。请尝试下一步
消息。我找不到任何错误。为什么这段代码不起作用?它应该成功发送请求和警报成功消息。
<?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>