简体   繁体   English

用js发布到用户墙

[英]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. 我们有一个留言板,我们希望允许我们的用户将自己的帖子交叉发布到他们的Facebook墙上。 We already have connected their user-account to their Facebook account in order to get their Facebook profile picture, and that works fine. 我们已经将他们的用户帐户连接到他们的Facebook帐户,以便获得他们的Facebook个人资料图片,并且效果很好。

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."). 我尝试按照此处的指南(https://developers.facebook.com/docs/reference/dialogs/feed/)进行操作,第一个示例运行良好,但我们真的不希望出现对话框,因此我尝试了“等效于Graph API”,但始终收到oauth异常#200(“此API调用需要有效的app_id。”)。

I checked FB.getLoginStatus and I am connected and executing FB.getAccessToken() gives me a an access token. 我检查了FB.getLoginStatus并已连接,执行FB.getAccessToken()给我一个访问令牌。

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. 我可以获取访问令牌,并验证登录的Facebook用户(我)已与匹配app_id的应用程序连接。

I can also invoke the message dialog using FB.ui with the stream.publish method. 我也可以使用FB.ui和stream.publish方法来调用消息对话框。

What I can't figure out, is how to transparently post my local comment to my Facebook page without bringing up the message dialog. 我不知道的是如何在不弹出消息对话框的情况下将本地评论透明地发布到我的Facebook页面。

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('الحمد لله');
              }
          }

                     );
      });
  }          

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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