3
votes

I've been Googling for 2 days, and can't find anything definitive. All results I've come across use deprecated code that no longer works. Please help.

I need a button that on click...

  1. Checks for extended permissions
  2. If permissions are not already granted, request them (user_likes, offline_access, publish_stream)
  3. After getting permissions, publish post to user's wall
  4. Allow me to push wall posts to users while they are offline

Can someone please assist?

1
Thanks to OffBySome for this example. Looking at it, I can see that I was very close to the solution, but missed the FB.login inclusion with response.authResponse. I will implement this tonight, and report my findings.Steve
With regard to the offline_access, can anyone confirm that this permission is not needed in order to post without user interaction? I understand that this is a bit of a grey area, but the user is aware that this would be taking place, and must specifically choose to allow it. It was my understanding, however, that the ability to post to an offline user's wall required this, as the auto-post: true was disabled. Using the user id, I just need to include the auth token without needing offline_access?Steve
I implemented the example posted by OffBySome last night, and it worked beautifully. Thank you :)Steve

1 Answers

9
votes

It's pretty simple. You can call FB.login to get extended permissions. Then you can call FB.ui to post a status (or FB.api to call /me/feed to post without user interaction, which is frowned upon). To be able to push wall posts at a later date you would need to store the access_token on your server for later use.

<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<a href="#" onclick="return postToWall();">Post To Wall</a>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({ appId: '**appID**', status: true, cookie: true, xfbml: true, oauth: true });

  function postToWall() {  
    FB.login(function(response) {
      if (response.authResponse) {
        FB.ui({
            method: 'feed', 
            name: 'Facebook Dialogs',
            link: 'https://developers.facebook.com/docs/reference/dialogs/',
            picture: 'http://fbrell.com/f8.jpg',
            caption: 'Reference Documentation',
            description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
        },
        function(response) {
          if (response && response.post_id) {
            alert('Post was published.');
          } else {
            alert('Post was not published.');
          }
        });
      } else {
        alert('User cancelled login or did not fully authorize.');
      }
    }, {scope: 'user_likes,offline_access,publish_stream'});
    return false;
}
</script>
</body>
</html>