using facebook stream publish

2019-04-02 18:31发布

I want to publish a URL as an attachment to a friends wall:

var attachment={'name':'favor','href':'http://128.196.239.71/movie.php?mid=<?php echo  $_GET['mid']; ?>'};
                                         Facebook.streamPublish('',attachment,null,friends[i],comment,callback);

Doing the above gives me a Facebook undefined, what should I do to remedy this?

Do I need to set a special permission in order to do this to the sender of this message?

1条回答
时光不老,我们不散
2楼-- · 2019-04-02 18:57

You do need the stream.publish permission in order to use the stream.publish method or the equivalent graph API call.

You can check that the user has already granted this permission with something like this:

FB.getLoginStatus(function(response) { if (response.perms) { /* check perms */ } })

You can request the permission with something like this:

FB.login(function(response) { /* check perms */ }, {scope: 'publish_stream'})

Then in the response you can check to see if it was actually granted, then you should be able to do stream publish calls.

However, I don't recognize the format of your call "Facebook.streamPublish". I think the new API requires you to do a call more like

FB.api({method: 'stream.publish', message: 'hello'}, function(response) {})

Alternatively to all this, you can use the dialogs API to create a post and show it to the user, and have them approve it or disapprove it. This does not require the stream.publish permission. Something like this (the example given in the FB.ui API docs):

 FB.ui(
   {
     method: 'feed',
     name: 'Facebook Dialogs',
     link: 'http://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.',
     message: 'Facebook Dialogs are easy!'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
 );

At the rate Facebook changes, I hope some of this information is still accurate by the time you read it (or even accurate to begin with).

查看更多
登录 后发表回答