用js发布到用户墙

时间:2012-06-26 09:36:10

标签: javascript facebook facebook-oauth

我们有一个评论板,我们希望允许我们的用户将他们的帖子交叉发布到他们的Facebook墙上。我们已经将他们的用户帐户连接到他们的Facebook帐户,以获得他们的Facebook个人资料图片,并且工作正常。

我尝试按照此处的指南(https://developers.facebook.com/docs/reference/dialogs/feed/)进行操作,第一个示例正常,但我们真的不想提出对话框,所以我尝试了“Graph API Equivalent”,但不断获得oauth异常#200(“此API调用需要有效的app_id。”)。

我检查了FB.getLoginStatus并且我已连接并执行FB.getAccessToken()为我提供了一个访问令牌。

我没有得到什么?

修改

是的,代码......现在我有这个:

<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>

我可以获取访问令牌并验证登录的Facebook用户(我)是否已与匹配app_id的应用程序相关联。

我也可以使用FB.ui和stream.publish方法调用消息对话框。

我无法弄清楚的是,如何透明地将我的本地评论发布到我的Facebook页面,而不会显示消息对话框。

任何指针?

提前谢谢:-) 马丁

1 个答案:

答案 0 :(得分:1)

马丁,

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

                     );
      });
  }          
相关问题