使用facebook javascript sdk发布到朋友墙 [英] posting to friends wall using facebook javascript sdk

查看:59
本文介绍了使用facebook javascript sdk发布到朋友墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用facebook javascript SDK发布到朋友墙?

How can I post to a friends wall using the facebook javascript SDK?

推荐答案

除了@ifaour关于FB.api ...的答案

In addition to @ifaour's answer on FB.api...

  • FB.init
  • 中设置oauth和状态参数
  • 通过FB.login
  • 请求扩展权限publish_stream
  • Set oauth and status parameters in FB.init
  • Request extended permission, publish_stream, via FB.login

其他资源:

使用facebook流发布

完整示例...

<script>

window.fbAsyncInit = function()
{
    FB.init({
        appId  : 'APP_ID',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true , // parse XFBML
        oauth : true // Enable oauth authentication
    });

    FB.login(function(response)
    {
        if (response.authResponse)
        {
            alert('Logged in!');

            // Post message to friend's wall

            var opts = {
                message : 'Post message',
                name : '',
                link : 'http://www....',
                description : 'Description here',
                picture : 'http://domain.com/pic.jpg'
            };

            FB.api('/FRIEND_ID/feed', 'post', opts, function(response)
            {
                if (!response || response.error)
                {
                    alert('Posting error occured');
                }
                else
                {
                    alert('Success - Post ID: ' + response.id);
                }
            });
        }
        else
        {
            alert('Not logged in');
        }
    }, { scope : 'publish_stream' });
};

</script>

<!-- FACEBOOK -->        
<div id="fb-root"></div>
<script>
(function() {
  var e = document.createElement('script');
  // replacing with an older version until FB fixes the cancel-login bug
  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  //e.src = 'scripts/all.js';
  e.async = true;
  document.getElementById('fb-root').appendChild(e);
  }());
</script>
<!-- END-OF-FACEBOOK -->

这篇关于使用facebook javascript sdk发布到朋友墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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