通过我的网站发布到Facebook墙

问题描述 投票:0回答:2

当我在文本框上键入一些内容并上传图像并提交时,帖子应该在特定用户的Facebook时间轴上发布。这是我写的代码,但它不起作用:

<html>
<head>
<script src='http://connect.facebook.net/en_US/all.js'></script>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'App ID', // App ID
    channelUrl : '//mynetwork.net/', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

  FB.Event.subscribe('auth.authResponseChange', function(response) {
    if (response.status === 'connected') {
      testAPI();
    } else if (response.status === 'not_authorized') {
      FB.login();
    } else {
      FB.login();
    }
  });
  };

  (function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
  }(document));

  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Good to see you, ' + response.name + '.');
    });
  }
</script>

<script>
var params = {};
params['message'] = 'Message eqwe';
params['name'] = 'wqe wqeweq Name';
params['description'] = 'wqe wDescription';
params['link'] = 'https://www.facebook.com/nvidarshana?fref=ts';
params['picture'] = 'http://summer-mourning.zoocha.com/uploads/thumb.png';
params['caption'] = 'Caption';

FB.api('/me/feed', 'post', params, function(response) {
  if (!response || response.error) {
    console.log(response.error);
    alert(response.error);
  } else {
    alert('Published to stream - you might want to delete it now!');
  }
});
</script>

<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>
</body>
</html>

我已更新我的代码,仍然收到错误

“对象{消息:”必须使用活动访问令牌来查询有关当前用户的信息。“,键入:”OAuthException“,代码:2500}”

javascript facebook facebook-graph-api facebook-javascript-sdk facebook-apps
2个回答
0
投票

如果您的用户正在进行会话,请替换以下代码 -

FB.api('/My_Access_Token/feed'

与 -

FB.api('/me/feed'

0
投票

在下面的代码中插入代码,以显示在墙上发布的按钮。编辑相关文本。

<div id="fb-root"></div>
       <script> 

 window.fbAsyncInit = function() { 

 FB.init({appId: "YOUR APP ID FROM STEP 3", status: true, cookie: true, 

 xfbml: true}); 

 }; 

 (function() { 

 var e = document.createElement("script"); e.async = true; 

 e.src = document.location.protocol + 

 "//connect.facebook.net/en_US/all.js"; 

 document.getElementById("fb-root").appendChild(e); 

 }());

 function streamPublish(){


FB.ui(
   {
     method: 'stream.publish',display:'popup';
<dd>
     message: 'getting educated about Facebook Connect',
     attachment: {
       name: 'Connect',
       caption: 'The Facebook Connect JavaScript SDK',
       description: (
         'A small JavaScript library that allows you to harness ' +
         'the power of Facebook, bringing the user\'s identity, ' +
         'social graph and distribution power to your site.'
       ),</dd>


‘media’: [{ 'type': 'image',


'src': 'http://www.yoursite.com/images/facebook_icon.png',


'href': fb_root()}] ,



<dd>
       href: 'http://github.com/facebook/connect-js'
     },
     action_links: [
       { text: 'Code', href: 'http://github.com/facebook/connect-js' }
     ],
     user_message_prompt: 'Share your thoughts about Connect'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
 );

 } </script>


</dd>
<dd></dd>

通过链接调用streamPublish函数。您可以使用CSS来更改链接/按钮的外观。

<a onclick=”streamPublish();” >Click to Publish on Facebook wall</a>

如果没有弹出发布窗口,请尝试将display:value设置为'dialog'

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.