将js sdk发布到pagewall

时间:2013-10-17 13:20:26

标签: facebook facebook-javascript-sdk feed

我试图通过js sdk将帖子发送到管理员的页面墙上。我已经做到了,我可以为自己(我的个人用户)做到这一点,但我不能让它作为"页面"工作。

<div id="fb-root"></div>
    <script type="text/javascript">
        function SendToFacebook()
        {
        window.fbAsyncInit = function () {
            // init the FB JS SDK
            FB.init({
                appId: '**CORRECT ID**',                        // App ID from the app dashboard
                channelUrl: '**MYPAGE**/channel.html', // Channel file for x-domain comms
                status: false,                                 // Check Facebook Login status
                xfbml: true                                  // Look for social plugins on the page
            });

            FB.ui(
               {
                   method: 'feed',
                   name: 'MyFeed',
                   link: '',
                   // picture: '',
                   caption: 'My caption',
                   description: 'test',
                   message: 'MESSAGE?',
               },
               function (response) {
                   if (response && response.post_id) {
                       alert('Delat på facebook.');
                   } else {
                       alert('Inte delat på facebook.');
                   }
               }
             );
            // Additional initialization code such as adding Event Listeners goes here
            };

        // Load the SDK asynchronously
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js";
            fjs.parentNode.insertBefore(js, fjs);
        } (document, 'script', 'facebook-jssdk'));
        }
    </script>

这会发布到我自己的用户页面,我已经尝试过&#34;到&#34;参数,但它将我的个人用户的帖子发送到页面。有没有办法通过登录功能来做到这一点? 请记住,我是相当新的,所以演示和例子是受欢迎的。

2 个答案:

答案 0 :(得分:5)

经过艰苦的工作后,我得到了它的工作,如果有任何人感兴趣的话我是怎么做的。

<script type="text/javascript">

        function SendToFacebook()
        {
            window.fbAsyncInit = function () {
                // init the FB JS SDK
                FB.init({
                    appId: '***',                        // App ID from the app dashboard
                    channelUrl: '***', // Channel file for x-domain comms
                    status: false,                                 // Check Facebook Login status
                    xfbml: true                                  // Look for social plugins on the page
                });


                FB.login(function (response) {
                    FB.api('/me/accounts', function (apiresponse) {

                        var data = {
                            message: "mymessage",
                            display: 'iframe',
                            caption: "caption",
                            name: "name",
                            description: "description",
                            to: **wallid**,
                            from: **wallid**
                        };

                        FB.api('/**wallid**/feed', 'post', data, function () {
                            console.log(arguments);
                        });


                    });

                }, { scope: 'manage_pages' });

            };
            // Load the SDK asynchronously
            (function (d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) { return; }
                js = d.createElement(s); js.id = id;
                js.src = "//connect.facebook.net/en_US/all.js";
                fjs.parentNode.insertBefore(js, fjs);
            } (document, 'script', 'facebook-jssdk'));
        }
        </script>

答案 1 :(得分:0)

我找到了这个解决方案而且我试过了,虽然我不知道3年前它是怎么回事,现在你需要附加你通过/我/账户呼叫接收的页面访问令牌(你也必须是该页面的管理员等) )所以今天的工作解决方案看起来像这样:

FB.api('/me/accounts', function (apiresponse) {
              console.log(apiresponse);
              var data = {
                  message: "mymessage",
                  //display: 'iframe',
                  caption: "caption",
                  picture: 'www.bla.com/image.jpg',
                  link: 'www.facebook.com',
                  name: "name",
                  description: "description",
                  to: **APP IP**,
                  from: **APP IP**,
                  access_token: apiresponse.data[0].access_token
              };

              FB.api('/**APP IP**/feed', 'post', data, function () {
                  console.log(arguments);
              });
          });