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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:57:36+00:00 2026-06-04T08:57:36+00:00

I’m having a bit of an issue trying to get some PHP code to

  • 0

I’m having a bit of an issue trying to get some PHP code to work with the Open Graph API provided by Facebook.

I have some PHP code that takes a url and returns the number of comments on that page that were made using the Facebook Comments plugin.

I know the code works, however, there is a small problem.

When I try my code, it doesn’t show any information. When I check in the API Explorer provided by Facebook, the information I want is there. The only difference is that when using the API explorer an Access Token is being used.

The code I’m running is trying to get the Graph data for pages on the same domain. This is not something that requires the person to authorize our application either, as it makes no sense to ask for authorization just to tell someone how many comments have been made on a page.

So my question is, how do I include an access token in the code below:

function fb_comment_count($url = '') {
$filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
$json = json_decode($filecontent);
$count = $json->$url->comments;
if ($count == 0 || !isset($count)) {
    $count = 0;
}
echo $count;
}

Right now the only problem is with this https://graph.facebook.com/?ids=’ . $url it is returning empty, but the API Explorer shows the proper information when I use the same URL. Can an Access Token be included in this somewhere, or is there something I’m missing?

  • 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-04T08:57:37+00:00Added an answer on June 4, 2026 at 8:57 am

    I actually ended up using this code, which allow me to get more than just comment counts (it uses the Facebook PHP SDK):

    <?php
    // Stats taken from link_stats table
    // Documentation: http://developers.facebook.com/docs/reference/fql/link_stat/
    function FBLinkStats($url,$type){
    
    $fbconfig['appid' ]  = "###########";
    $fbconfig['secret']  = "###########";
    include_once "facebook.php";
    
    $facebook = new Facebook(array(
        'appId'  => $fbconfig['appid' ],
        'secret' => $fbconfig['secret'],
        'cookie' => true
    ));
    
    $fql = "SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url = '".$url."' ";
    $param  =   array(
        'method'    => 'fql.query',
        'query'     => $fql,
        'callback'  => ''
    );
    $fqlResult   =   $facebook->api($param);
    return $fqlResult[0][$type];
    }
    ?>
    

    The function takes two variables, the URL of the page you are fetching information on, and the stat you want returned, which can be found on this page: http://developers.facebook.com/docs/reference/fql/link_stat/

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.