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 8288827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:21:36+00:00 2026-06-08T12:21:36+00:00

Could someone please give me an example of posting a like for a facebook

  • 0

Could someone please give me an example of posting a like for a facebook post from an external app with an authenticated user?

Say I have a feed pulling posts from facebook, and I want to create a button that lets the user like a post from my app. On click of this button, how could I best create that like so that the post is updated on Facebook with the user’s like?

My thoughts are that I could make a javascript onclick function that ajaxes to a php script that does something like – $facebook->api(“/$id/likes”,’POST’); , but do I need to re-initialize facebook from that page before I can make this call? or send my access token etc.? This is what kind of confuses me about this server-side method. How do you make this call upon click? An example would be really helpful! Thanks in advance!!

  • 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-08T12:21:37+00:00Added an answer on June 8, 2026 at 12:21 pm

    Okay so finally found a decent solution, and without curl. This is the script I call to in my ajax function onclick:

    <?php
    $access_token = $_GET['token'];
    
    $post_id = $_GET['id'];
    
    function do_post_request($url, $data, $optional_headers = null)
    {
    $params = array('http' => array(
              'method' => 'POST',
              'content' => $data
            ));
    if ($optional_headers !== null) {
      $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if (!$fp) {
      echo "error";
    }
    $response = @stream_get_contents($fp);
    if ($response === false) {
      throw new Exception("Problem reading data");
    }
      return $response;
    }
    
    $data = "access_token=".$access_token;
    
    $url = 'https://graph.facebook.com/'.$post_id.'/likes';
    
    $result = do_post_request($url, $data, $optional_headers = null);
    ?>
    

    Also in my tested working code the $post_id has the user id whose post it was first like this: SOURCEUSERID_POSTID

    Got this solution from a combination of this post – http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

    and this one – Like posts over Facebook graph api

    hope this helps someone else out !

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

Sidebar

Related Questions

Please could someone give me an example in batch of something like: IF test.txt
Could someone please give me an example on how can I convert a byte[]
Could someone please give an example of how to use ling to query over
Could someone please give me a example of a function that would use this
Could someone please give me a Perl example on how to load an image
Could someone please give me simple websocket code. I am creating websocket example but
Could someone please give me a link on how to create a query in
Could someone please tell me why this <%= destroy_password_url @user.password_reset_token %> generates http://localhost:3000/api/destroy_password.4G5EoRVYMUAtiIKqOerKsw routes.rb
Could someone please give me some advice/ideas about how to deal with the situations
Could someone please give a list of all the applescript data types (the things

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.