简体   繁体   English

使用facebook javascript sdk将评论发布到某人的个人资料帖子或页面帖子或群组帖子

[英]Post comments to someones profile post or page post or group post using facebook javascript sdk

I want to post comments to someone's Facebook profile post or page post or group post using the Facebook Javascript SDK with an access token and Graph API . 我想使用带有访问令牌和Graph APIFacebook Javascript SDK将评论发布到某人的Facebook个人资料帖子或页面帖子或群组帖子。

I can generate an application access token from a current logged in user with publish_stream permission. 我可以从具有publish_stream权限的当前登录用户生成应用程序访问令牌。 How do I use the Javascript SDK call using post id so that a user can comment from outside Facebook, that is from my site where all page/profile/group posts are shown? 如何使用带有post id的Javascript SDK调用,以便用户可以从Facebook外部(即在我的网站上显示所有页面/个人资料/论坛帖子的位置)发表评论?

I tried the PHP SDK, but is not working on the server site. 我尝试了PHP SDK,但无法在服务器站点上工作。

Assuming user already logged in and access token has publish_stream permissions, you should call 假设用户已经登录并且访问令牌具有publish_stream权限,则应调用

FB.api('/'+ _POST_ID_HERE_ +'/comments', 'POST', { message:"Your comment text" },
       function(response)
       {
            if (response && !response.error && response.id)
            {
                 alert('New comment id = '+response.id);
            }
       });

function Comment_Clicked(pid) { FB.init({ appId : '472562079456084', status : true, // check login status //channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML //oauth:true }); 函数Comment_Clicked(pid){FB.init({appId:'472562079456084',status:true,//检查登录状态// channelUrl:'//WWW.YOUR_DOMAIN.COM/channel.html',// Channel File cookie: true,//启用cookie以允许服务器访问会话xfbml:true //解析XFBML // oauth:true});

    FB.login(function(response) {
        if (response.status=='connected') {
            if (response.authResponse.accessToken) {
                var token = response.authResponse.accessToken;      

                FB.api('/'+pid+'/comments?access_token='+token+'', 'POST',{ message:'test' }, function(response) {
                  if (!response || response.error) {
                    ms_js("#msfb-error-comlike").text("Errors you may not have permissions ");
                  } else {
                    ms_js("#msfb-error-comlike").text("Post success");
                  }
                });
                //window.location = "<? echo $absolute_url; ?>&temptoken="+ token +"";
            } else {
                // user is logged in, but did not grant any permissions
                alert('You can create an access token only for your own profiles and pages.');
            }
        } else {
            // user is not logged in
            alert('To use fb.wall you have to create an access token.');
        }
    }, {scope:'read_stream,publish_stream'}); //exclude publish_stream,publish_actions  

} }

this my complete function which does the comment.here i am generating a access token by app id.is it right? 这是我完成评论的完整功能。在这里,我正在通过应用程序ID生成访问令牌。对吗? by a app access token a user can comment on another page,profile post instead of his page or profile post?! 通过应用访问令牌,用户可以在其他页面,个人资料帖子而不是他的页面或个人资料帖子上发表评论? things go ok so is using. 一切正常,因此正在使用。 @Const actually publish_stream permission works for another user performing comment to another user profile post which i tested.but for the user for which problem is still problem, dont know why!.generating token giving all permissions using javascript sdk in my local site not working but works when i generate here - developers.facebook.com/tools/explorer.... @Const实际上publish_stream权限适用于对我测试过的另一个用户个人资料帖子执行评论的另一个用户。但是对于仍然存在问题的用户,不知道为什么!在我的本地站点中使用javascript sdk生成赋予所有权限的令牌不起作用但是当我在这里生成时可以工作-developers.facebook.com/tools/explorer ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM