简体   繁体   中英

post to users wall with js

We have a comment-board, where we want to allow our users to cross-post their posts to their Facebook wall. We already have connected their user-account to their Facebook account in order to get their Facebook profile picture, and that works fine.

I tried to follow the guide here (https://developers.facebook.com/docs/reference/dialogs/feed/) and the first example works fine, but we would really prefer not to bring up a dialog, so I tried the "Graph API Equivalent", but keep getting an oauth exception #200 ("This API call requires a valid app_id.").

I checked FB.getLoginStatus and I am connected and executing FB.getAccessToken() gives me a an access token.

What am I not getting?

EDIT

Yes, code ... right now I have this:

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
    appId : 'APP_ID',
    status : true,
    cookie : true,
    xfbml : true
});
FB.UIServer.setLoadedNode = function(a,b){FB.UIServer._loadedNodes[a.id]=b;};
};
(function(d){
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    d.getElementsByTagName('head')[0].appendChild(js);
}(document));

</script>

I can get an access token and verify the logged in Facebook user (me) has connected with the app matching the app_id.

I can also invoke the message dialog using FB.ui with the stream.publish method.

What I can't figure out, is how to transparently post my local comment to my Facebook page without bringing up the message dialog.

Any pointers?

Thank you in advance :-) Martin

Martin,

function shareWithFacebook() {
      var photoName;
      var photoUrl;
      photoName = document.getElementById("ImageName").value;
      photoUrl = document.getElementById("ImageUrl").value;
      debugger;
      var ui;
      var publish;
      FB.getLoginStatus(function (response) {
          FB.api('/me/feed', 'post', {
              message: 'I just added an image of ' + photoName + ' on http://www.yoursite.com/',
              name: photoName,
              link: 'http://www.yoursite.com/',
              picture: photoUrl,
              actions: [{ name: 'Photo', link: 'http://www.yoursite.com/'}]

          }, function (response) {
              if (!response || response.error) {
                  alert('Couldn\'t post to Facebook!');
              }
              else {
                     alert('الحمد لله');
              }
          }

                     );
      });
  }          

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM