2016-03-15 121 views
-7

我需要从网站发送fb邀请并计算发送邀请的数量。如果发送的邀请数量是5,则只有内容会显示,否则会显示错误消息。我是新的API,所以请建议我使用PHP什么和如何做。朋友邀请并计算发送的邀请

等待最早的回应。

感谢

+1

Facebook平台政策不允许 – WizKid

+0

那该怎么办呢? – DeepikaG

+0

然后你不这样做。或者你这样做,你的应用程序将被删除 – WizKid

回答

0
We can test from localhost? 
<?php 
// PATH TO THE FB-PHP-SDK 

require_once 'src/facebook.php'; 
$facebook = new Facebook(array(
    'appId' => '220998421586280', 
    'secret' => 'fb99179c8d2d3b8389f24818a3879bb5' 
)); 

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

if (empty($user)) { 
    echo("<script> top.location.href='" . $loginUrl . "'</script>"); 
    exit(); 
} 
?> 
<!doctype html> 
<html> 
<head> 
<title>FB</title> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> 
</head> 
<body> 
<div id="fb-root"></div> 

<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: '220998421586280', 
      status: true, 
      cookie: true, 
      oauth: true 
     }); 
    }; 
    $(document).ready(function(){ //alert(1); 
    $('a').click(sendRequest); 
    }); 
    function sendRequest() { 
     FB.ui({ 
      method: 'apprequests', 
      message: 'I want to give you this flower!', 
      title: 'Give a flower to some of your friends', 
      data: '{"item_id":1254,"item_type":"plant"}' 
     }, 
     function (response) { 
      //alert(JSON.stringify(response)); 
      if (response && response.request && response.to) { 
       var request_ids = []; 
       for(i=0; i<response.to.length; i++) { 
        var temp = response.request + '_' + response.to[i]; 
        request_ids.push(temp); 
       } 
       var requests = request_ids.join(','); 
       $.post('handle_requests.php',{uid: <?php echo $user; ?>, request_ids: requests},function(resp) { 
        // callback after storing the requests 
       }); 
      } else { 
       alert('canceled'); 
      } 
     }); 
     return false; 
    } 

     // Load the SDK Asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 
</script> 

<a href="javascript:void(0);">Send</a> 

</body> 
</html> 
Getting error like 
Game Requests are only available to games.