2

我试图通过 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>

这发布到我自己的用户页面,并且我尝试了“to”参数,但它将帖子从我的个人用户发送到页面。有没有办法通过登录功能做到这一点?请记住,我对此相当陌生,因此欢迎演示和示例。

4

2 回答 2

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>
于 2013-11-13T13:31:43.277 回答
0

我找到了这个解决方案并尝试了它,虽然我不知道 3 年前的情况,但现在你需要附加通过 /me/accounts 调用收到的页面访问令牌(你也必须是该页面的管理员等)所以今天工作解决方案可能如下所示:

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);
              });
          });
于 2016-10-20T11:51:03.987 回答