Facebook-如何使用javascript sdk向公司发帖?

Facebook-如何使用javascript sdk向公司发帖?,facebook,integration,Facebook,Integration,我是facebook发帖新手,但在使用用户帐户离线发帖方面取得了一些成功,但无法使用公司页面离线发帖 我已经通过自己的个人Facebook帐户创建了自己的“Facebook应用程序”,名为“Nicks海报应用程序”。我已经为我的个人页面和公司页面的应用程序授予了三个权限(脱机访问、读取流、发布流)。 我通过对每个帐户执行以下步骤来做到这一点 Creating the app... 1. Login to facebook with the account you want linke

我是facebook发帖新手,但在使用用户帐户离线发帖方面取得了一些成功,但无法使用公司页面离线发帖

我已经通过自己的个人Facebook帐户创建了自己的“Facebook应用程序”,名为“Nicks海报应用程序”。我已经为我的个人页面和公司页面的应用程序授予了三个权限(脱机访问、读取流、发布流)。 我通过对每个帐户执行以下步骤来做到这一点

Creating the app...
1.       Login to facebook with the account you want linked to the app
2.       Follow this link http://www.facebook.com/developers/apps.php#!/developers/createapp.php
3.       Create your app and take a note of you App Id and your App secret Id.

Giving the correct rights to the app and getting the access_token..
Method 1:
1.       Get the account in question to login to facebook
2.       However you like, direct the user to this link (replacing <App-Id> with the App Id of the created app) https://graph.facebook.com/oauth/authorize?client_id=<App-Id>&scope=offline_access,read_stream&redirect_uri=http://www.facebook.com/connect/login_success.html
3.       Take a note of the result of the “code” querystring.
4.       Goto this url (replace “<APP-ID>” with you appId and “<APP-SECRET>” with your apps secret id and “<code>” with the copied code)
https://graph.facebook.com/oauth/access_token?client_id=<APP-ID>&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=<APP-SECRET>&code=<code>
5.       Copy what you see, minus the expires querystring.  That is your access_token.
在我拥有这两个帐户的访问令牌后,我使用此代码发布了这篇文章

<!-- 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 -->
<script>
    //initialise
    window.fbAsyncInit = function () {
        FB.init({
            appId: '351023398277068',
            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
        });
    };
    function sendPost(inMessage) {
        var opts = {
            message: inMessage,
            access_token: '<SAVED-TOKEN>'
        };

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

</script>

(功能(){
var e=document.createElement('script');
//替换为旧版本,直到FB修复取消登录错误
e、 src=document.location.protocol+'//connect.facebook.net/en_US/all.js';
//e、 src='scripts/all.js';
e、 异步=真;
document.getElementById('fb-root').appendChild(e);
} ());
//初始化
window.fbAsyninit=函数(){
FB.init({
appId:'351023398277068',
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true,//解析xfbml
oauth:true//启用oauth身份验证
});
};
函数sendPost(inMessage){
变量选项={
消息:inMessage,
访问\u令牌:“”
};
api('/me/feed',post',opts,function(response){
如果(!response | | response.error){
警报(“发生过账错误”);
}
否则{
警报('Success-Post ID:'+response.ID);
}
});
}
当使用perameter“Test post”执行“sendPost”命令时,它将对我的个人帐户起作用(前提是我将访问令牌放置到位)。这对我的公司页面不起作用,我不知道为什么(我确实把我的acess_令牌放好了)

Facebok也没有很好地记录这一点,这使得它很难取得进展,有人知道为什么这不适用于公司页面吗

提前感谢。

您可以将“to”参数设置为指向要发布到的页面,“如果您希望将页面作为应用程序发布到页面,则需要管理页面perms。”

<div id="msg"></div>
<script>
// uid is the id of the page or user you wish to post to.
      function feedthis2(uid) {

        // calling the API ...
        var obj = {
        method: 'feed',
        to: ''+uid+''    
        };

        function callback(response) {
          document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
        }

        FB.ui(obj, callback);
      }
    feedthis2('AnotherFeed'); // to http://facebook.com/anotherfeed
    //feedthis2('135669679827333');
</script>

//uid是要发布到的页面或用户的id。
函数feedthis2(uid){
//正在调用API。。。
var obj={
方法:“提要”,
到:“”+uid+“”
};
函数回调(响应){
document.getElementById('msg').innerHTML=“Post ID:”+response['Post_ID'];
}
FB.ui(obj,回调);
}
feedthis2('AnotherFeed');//到http://facebook.com/anotherfeed
//feedthis2('135669679827333');

我不想在另一个用户帐户上发帖,只想在自己的新闻提要上发帖,或者像你说的那样“作为你的页面发布到你的页面”。什么是“管理页面perms”。它与“脱机访问”类似吗?目前我唯一授权的权限是“脱机访问,阅读流”。我还使用了“发布流”但是没有乐趣。好的,我已经找到了“管理页面”权限,现在正在使用我的新访问令牌。这仍然不起作用,它仍然适用于我的个人帐户。有什么想法吗?如果我把你弄糊涂了,很抱歉,要以页面的形式发布到页面,你需要以页面的形式登录并获得页面访问令牌。创建一个append your page acce3ss标记,将post设置为页面id,然后您的post应该可以工作。很好。您发送到那里的链接将我带到一个帮助我获取“页面访问令牌”的页面。我所做的就是使用“页面访问令牌”,而不是“用户访问令牌”,并成功地将其发布到公司新闻提要(使用上面的代码)。它通过nicks海报应用程序制作了一篇标准帖子,这是完美的。再次感谢。完成:)我是一个新用户,所以我不能投票。。希望其他人也会这样做。