Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7709777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:56:50+00:00 2026-06-01T00:56:50+00:00

I have a Facebook application, a Facebook page and a website. When someone adds

  • 0

I have a Facebook application, a Facebook page and a website. When someone adds a comment to my website, I retrieve the comment text from the code below. What I want to do after that is to let my Facebook application post the same comment text to my Facebook page.

This is the JavaScript code I have so far on my website:

 window.fbAsyncInit = function() {
     FB.init({
         appId: " . drupal_to_js($appid) . ",
         status: true,
         cookie: true,
         xfbml: true,
         channelUrl: " . drupal_to_js($channel_url) . "
     });

     FB.Event.subscribe('comment.create', function(response) {
        var commentQuery = FB.Data.query('SELECT text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');

        FB.Data.waitOn([commentQuery], function () {
            var commentRow = commentQuery.value[0];
            var commentText = commentRow.text;

            //TODO Post commentText to the Facebook page.
        });
     });  };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:56:51+00:00Added an answer on June 1, 2026 at 12:56 am

    After an extensive search, here is the answer for those who are looking for it. Please read the comments inside the code, they will give you more information.

    window.fbAsyncInit = function() {
        FB.init({
            appId: " . drupal_to_js($appid) . ",
            status: true,
            cookie: true,
            xfbml: true,
            channelUrl: " . drupal_to_js($channel_url) . "
        });
    
        FB.Event.subscribe('comment.create', function(response) {  //trigger when comment is created
            var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
            var userQuery = FB.Data.query('SELECT name FROM user WHERE uid in (select fromid from {0})', commentQuery);
    
            FB.Data.waitOn([commentQuery, userQuery], function () {
              var commentRow = commentQuery.value[0];
              var userRow = userQuery.value[0];
    
              var commentText = commentRow.text;
              var commentUsername = userRow.name;
    
              //Call this function to send an Ajax request to Facebook.
              post_to_fb(commentText, commentUsername, response.href);
            });
        }); };
    
    //This function will post to a Facebook page that has the ID $fb_page_id.
    //The post format is like this, [NAME said:] POST e.g: [ObyYou said:] this is a test.
    //Of course, you can change the format the way you want.
    //You have to have an access key to have the permission to post on that page.
    //Use the two sites at the bottom of this answer for help, (remember if you
    //want to hard-code the access token, you have to create a permenant access token).
    //Note that some variables and functions are PHP, since my JavaScript code is
    //actually inside a PHP file.
    function post_to_fb(commentText, commentUsername, commentLink) {
        var strURL = 'https://graph.facebook.com/" . $fb_page_id . "/feed';
        var params = 'link=' + commentLink + '&message=[' + commentUsername +'+said:]+' + commentText + '&access_token=" . $fb_page_access_token . "';
    
        var xmlHttpReq;
        xmlHttpReq = new XMLHttpRequest();
        xmlHttpReq.open('POST', strURL, true);
        xmlHttpReq.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        xmlHttpReq.send(params);
    }
    

    Create A (permanent) access_token:

    http://www.testically.org/2011/09/27/5-steps-to-automatically-write-on-your-facebook-page-wall-using-the-graph-api-without-a-logged-in-user/

    http://php-academy.blogspot.com/2011/04/how-to-post-from-facebook-app-to.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Desktop Facebook application that allows the user to retrieve some
I have a facebook application and created an app page in the app settings.
We have a Facebook application implemented as tabs in a page. However, for certain
I have this facebook application which adds a custom tab to fan pages. You
I have a Facebook Application in order to manage comments on my web page,
I have a Facebook Application that installs on users' Page tabs. I would like
Say I have the website http://www.example.org and the corresponding Facebook page at http://www.facebook.com/example .
I have a facebook application and a tab page which links http://localhost/a/index.php , I
I have this Facebook application profile page: http://www.facebook.com/developers/editapp.php?app_id=122313254494566#!/apps/application.php?id=122313254494566 which is associated with my iframe-based
I have a facebook game application that is released at facebook platform at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.