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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:08:06+00:00 2026-06-11T23:08:06+00:00

i have put last 3 posts in web page , if user loged in

  • 0

i have put last 3 posts in web page , if user loged in he can add comment / like , problem is if user loged in and try add like or comment he is getting an permission error #200 , if i loged in i can add like or comment (application is for me) , am getting the all permission nedded from the user , so how can i give him permission to add like / comment.

CODE :

$facebook = new Facebook(array(
            'appId' => '',
            'secret' => '',
            'cookie' => true,
        ));

$user = $facebook->getUser();
if ($user) {  
    if (session_id()) {

    } else {
        session_start();
    }

    $access_token = $facebook->getAccessToken();
    //check permissions list

    $permissions_list = $facebook->api(
            '/me/permissions', 'GET', array(
        'access_token' => $access_token
            )
    );

    //check if the permissions we need have been allowed by the user
    //if not then redirect them again to facebook's permissions page

    $permissions_needed = array('publish_stream', 'read_stream', 'manage_pages');

    foreach ($permissions_needed as $perm) {
        if (!isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1) {
            $login_url_params = array(
                'scope' => 'publish_stream,read_stream,manage_pages',
                 'fbconnect' =>  1,
        'display'   =>  "page",
                'redirect_uri' => 'http://localhost/fb/index.php',
            );
            $login_url = $facebook->getLoginUrl($login_url_params);
            header("Location: {$login_url}");
            exit();
        }
    }
}else {

    //if not, let's redirect to the ALLOW page so we can get access
    //Create a login URL using the Facebook library's getLoginUrl() method

    $login_url_params = array(
        'scope' => 'publish_stream,read_stream,manage_pages',
                'fbconnect' =>  1,
        'display'   =>  "page",
        'redirect_uri'=>'http://localhost/fb/index.php',
    );
    $login_url = $facebook->getLoginUrl($login_url_params);

    //redirect to the login URL on facebook
    header("Location: {$login_url}");
    exit();
}

$logoutUrl = $facebook->getLogoutUrl();

and if the user click on like button :

            jQuery('ul.fb_list a').click(function(){

               var comm_id = jQuery(this).attr("class");

                    jQuery.post('https://graph.facebook.com/'+comm_id+'/likes/',{
                        access_token : "<?php echo $access_token ?>"

                    });
            });  
  • 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-11T23:08:07+00:00Added an answer on June 11, 2026 at 11:08 pm

    Double check and make sure your variable comm_id is formated with both the user id of the person who posted the post, and then the id of the post itself, with an underscore in between, like this – USERID_POSTID. This is how facebook gives it you if you call to the graph api

    $post_url = "https://graph.facebook.com/" . $user_id . "/posts?access_token=". urlencode($access_token);
    

    Not sure if you’re getting comm_id from another source or not. Also noticed in your code

    access_token : "<?php echo $access_token ?>"
    

    You forgot a semi-colon after the echo call. Should be this

      access_token : "<?php echo $access_token; ?>"
    

    Hope this helps. I see you’re using a lot of jquery to do the like functionality. I like to stick w/ server side code for stuff like this, I feel that it’s more stable for some reason.

    This is how I did it. I have a like button like this –

    echo '<div id="like_container-'.$i.'">
    <div id="like_count">'.$num_likes.'</div>'
    <a href="javascript:void()" onclick="fb_Like(\''.$post_id.'\',\''.$access_token.'\','.$num_likes.','.$i.')"><div class="unliked"></div></a>
    </div>';
    

    and fb_Like() is an ajax call, something like this –

    function fb_Like(post_id, token, num_likes, id){
    $.ajax({
    type: "GET",
    url: "likepost.php",
    data: 'id='+post_id+'&token='+token+'&likes='+num_likes,
    success: function(html)
    {
        $("#like_container-"+id).empty().html(html);
    
    }
    
    });
    }
    

    And the likepost.php page is a script similar to the one on this page

    Like a Facebook Post externally using Graph Api – example

    This worked really well for me. It also let’s me update the number of likes that the post has on the front end right above the like button if a like has been made. Good luck!

    UPDATE

    If you want to check if the user already likes a post, it’s pretty simple w/ the facebook graph api

    //Create Post Url
    $post_url = "https://graph.facebook.com/" . $Page/User_id . "/posts?access_token=". urlencode($access_token);
    
    //Get Json Contents
    $resp = file_get_contents($post_url,0,null,null);
    
    //Store Post Entries as Array
    $the_posts = json_decode($resp, true);
    
    foreach ($the_posts['data'] as $postdata) {
    
        foreach ($postdata['likes']['data'] as $like){
    
            if($like['id']==$user){
    
            $liked=1;
    
            }else{continue;}                                                
        }
    
        if($liked==1){
         //do something
        }
    
    }
    

    This assumes that you already have a facebook user id for the logged in user, in this example, stored in the variable $user.

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

Sidebar

Related Questions

Last night I tried to put together something that I have had working since
i have put my site in dropbox so you can see it http://dl.dropbox.com/u/13722201/Dorset%20Designs/home.html when
I have put together an image scroller using jquery, like this function rotateImages(whichHolder, start)
i have put fckeditor in jsp page. I want to get the value whatever
I have put the following method in my master page. It works when I
I am having a problem regarding a jquery dropdownmenu. I have put a slidedown
i have one jquery dialog which can show after click radiobutton. last time it
I want to have a user select a file and then have php put
(i have put the code at the end of my post) i would like
I have put together a navigation bar which expands a submenu on hover. See

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.