Letting user specify recipients within Feed Dialog

前端 未结 1 1671
说谎
说谎 2021-02-11 04:11

Currently, our app posts to users\' friends\' walls via Graph API. However, Facebook is deprecating this functionality so we are migrating to the Feed Dialog per Facebook\'s rec

相关标签:
1条回答
  • 2021-02-11 04:47

    OK, we found a workaround. The general idea:

    1. Display the Feed Dialog inline as an iframe (by specifying display=iframe)
    2. Create your own custom control for selecting a recipient Facebook username or id
    3. Reload the iframe asynchronously upon selecting a recipient or onblur, etc

    Some caveats/reasoning for above:

    • You can't use the JS SDK because it will launch the iframe version of the Feed Dialog as a modal lightbox (rather than inline in your page flow)
    • You'll need to implement a redirect page that does post processing, such as updating the state of the parent window, logging results, etc
    • For (2), the custom control can be as simple as a text input field, but you'll probably want at least some sort of autocomplete. This is actually not too tricky, as you grab your user's friend list with the https://graph.facebook.com/me/friends Graph API call.

    Here's a basic example using a simple text input:

    <html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    </head>
    <body>
    <div>
      Recipient's FB username:
      <input type="text" id="fb-recipient" placeholder="Recipient's FB username"></input>
      <input type="submit" id="fb-recipient-submit" value="Pick" />
    </div>
      <iframe id="fb-feed-dialog" width="586" height="330" frameborder="0" allowfullscreen></iframe>
    <script>
      $('#fb-recipient-submit').click(function(e){
        e.preventDefault();
        var feedUrl = 'https://www.facebook.com/dialog/feed?';
        feedUrl += 'display=iframe';
        feedUrl += '&app_id=' + 'YOUR_APP_ID';
        feedUrl += '&access_token=' + 'ACCESS_TOKEN';
        feedUrl += '&link=' + 'SHARE_LINK';
        feedUrl += '&redirect_uri=' + 'REDIRECT_URI';
        feedUrl += '&to=' + $('#fb-recipient').val();
        $('#fb-feed-dialog').attr( 'src', feedUrl );
      });
    </script>
    </body>
    </html>
    

    You can find a screenshot of a slightly more fleshed out solution at: http://i.imgur.com/0jTM391.png

    0 讨论(0)
提交回复
热议问题