Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

Simple Facebook Javascript post to stream example?

I'm trying to post to user stream, without user prompt. I cannot manage to find a code that works. Facebook JSDK is already loaded and I will insert the code inside:

FB.getLoginStatus(function(response){

to make sure the user is already logged to my application. Could you provide an example of publishing to the user stream using the publish_stream permission?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With Dialog

You need to use the Feed Dialog, with FB.ui():

function postToFeed() {
    // calling the API ...
    var obj = {
        method: 'feed',
        link: 'https://developers.facebook.com/docs/reference/dialogs/',
        picture: 'http://fbrell.com/f8.jpg',
        name: 'Facebook Dialogs',
        caption: 'Reference Documentation',
        description: 'Using Dialogs to interact with users.'
    };

    function callback(response) {
        document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
}

Documentation: https://developers.facebook.com/docs/reference/dialogs/feed/

Without Dialog

To make a post without the Dialog you need to use the FB.api():

var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

Documentation: https://developers.facebook.com/docs/reference/javascript/FB.api/

Direct URL

https://www.facebook.com/dialog/feed?
  app_id=APP_ID&
  link=https://YOUR_DOMAIN&
  picture=http://YOUR_DOMAIN/image.jpg&
  name=Facebook%20Dialogs&
  caption=API%20Dialogs&
  description=Using%20Dialogs%20to%20interact%20with%20users.&
  redirect_uri=http://YOUR_DOMAIN/response

Documentation: https://developers.facebook.com/docs/reference/dialogs/feed/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...