0

当我在文本框中输入一些内容并上传图像并提交时,该帖子应发布在特定用户的 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>

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

"Object {message: "必须使用活动访问令牌来查询当前用户的信息。", type: "OAuthException", code: 2500} "

4

2 回答 2

0

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

FB.api('/My_Access_Token/feed'

和 -

FB.api('/me/feed'
于 2013-10-03T06:59:55.477 回答
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'</p>

于 2013-10-03T07:02:37.400 回答