如何获取FB.api('/ me / feed','post',...工作? [英] How to get FB.api('/me/feed', 'post', ... to work?

查看:162
本文介绍了如何获取FB.api('/ me / feed','post',...工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用FB.api向我的饲料发布几个小时。我不能让它为我工作。我给予了该应用的权限。我可以使用PHP SDK发布到我的Feed,但是我必须使用JavaScript。

I've tried to use FB.api to post something to my feed for hours now. I can't get it to work for me. I gave the permissions to the app. I can post to my feed with the PHP SDK but I have to use JavaScript.

<button onclick="doPost()">Post to Stream</button>

<script>
window.doPost = function() {
  FB.api(
    '/me/feed',
    'post',
    { body: 'Trying the Graph' },
    Log.info.bind('/me/feed POST callback')
  );
};
</script>

有人可以给我一个使用FB.api发布到Feed的简单HTML页面的示例?

Can someone give me the example of a simple HTML page that uses FB.api to post to a feed?

推荐答案

嗯,我让它工作了。我不知道当我从头开始使用新的HTML文件时,第一次出现了什么问题。我希望它能帮助某人:

Well, I got it working myself. I'm not sure what was wrong the first time as I started from scratch with a new HTML file. I hope it will help someone:

    <!DOCTYPE html>
    <html xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
    </head>
    <body>

    <a href="#" onClick="postToFacebook()">Post to Facebook</a>

    <script>
    function postToFacebook() {
        var body = 'Reading Connect JS documentation';

        FB.api('/me/feed', 'post', { body: body, message: 'My message is ...' }, function(response) {
          if (!response || response.error) {
            alert('Error occured');
          } else {
            alert('Post ID: ' + response);
          }
        });
    }
    </script>

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId  : 'YOUR APP ID GOES HERE',
          status : true, // check login status
          cookie : true, // enable cookies to allow the server to access the session
          xfbml  : true  // parse XFBML
        });
      };

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>

    </body>
    </html>

这篇关于如何获取FB.api('/ me / feed','post',...工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆