Facebook FQL / Graph - Get all current pokes

2019-05-28 22:03发布

问题:

How can I get my current pokes (and pokes back)?

Normaly they must be in the table "notification" ... I am confused.

Hope someone can help me.

回答1:

Here is a working example that prompts for read_mailbox permission and uses /me/pokes to retrieve a users pokes. This can be done in any server side language too using the same logic.

Get Pokes:

<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<a href="#" onclick="getPokes();return false;">Get Pokes</a>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({ appId  : '**yourAppID', status : true, cookie : true, xfbml  : true });

  function getPokes() {  
    FB.login(function(response) {
      if (response.session && response.perms) {
        FB.api('/me/pokes',  function(response) {
            for(var i=0; i < response.data.length; i++) {
              alert(response.data[i].from.name + " poked you.");
            }
          }
        );
      }
    } , {perms:'read_mailbox'}); 
}
</script>
</body>
</html>

Poke back: To poke a user back, you would issue an HTTP Post to /userid/pokes but you need to get whitelisted by Facebook. Otherwise you will get this response:

{
  error: {
    type: "OAuthException",
    message: "(#3) Application does not have the capability to make this API call.",
  }
}


回答2:

Using the graph API, using the right access token of course (you need the "read_mailbox" permission"), access https://graph.facebook.com/me/pokes

Replace "me" in the graph API for a Facebook UID you have permission to access to.



回答3:

Here are the Facebook REST docs for how to get notifications, which should include Pokes.

"If you are building an application that notifies users of new messages/pokes/shares, we encourage you to use the following logic..."