CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    May 2012
    Posts
    13

    Total number of Facebook group members

    Hello, I am trying to understand how to display the total number of Facebook group members. I managed to put this code together, but when I load it the page is blank:

    Code:
    <?php
        require('facebook.php');
        $config = array(
            'appId' => 'MYAPPID',
            'secret' => 'MYSECRETID',
            'cookie' => true
        );
        $facebook = new Facebook($config);
        $query = urlencode('SELECT count(uid) from group_member WHERE gid = MYGROUPID limit 500 offset 500');
        try {
            $fbData = $facebook->api("/fql?q={$query}");
        } catch (FacebookApiException $e) {
            $fbData
    		 = $e->getResult();
        };
      var_dump($fbData);
    ?>
    Last edited by Mad_Griffith; May 18th, 2012 at 05:59 AM.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    You should be contacting Facebook first.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    Quote Originally Posted by PeejAvery View Post
    You should be contacting Facebook first.
    I already tried on the official Facebook Forums but was in vain

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    Well...I've never created any Facebook PHP apps, but one thing that comes directly to mind is that you aren't doing anything with the variable after sending your FQL query. Also, the group ID you're using only has 3 members anyway. So why are you limiting and offsetting by 500?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    Quote Originally Posted by PeejAvery View Post
    Well...I've never created any Facebook PHP apps, but one thing that comes directly to mind is that you aren't doing anything with the variable after sending your FQL query. Also, the group ID you're using only has 3 members anyway. So why are you limiting and offsetting by 500?
    Do you have any experience with FB PHP SDK? How do you suggest to end the code so that the results are shown?

    Thank you
    Last edited by Mad_Griffith; May 18th, 2012 at 05:56 AM.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    I don't use the Facebook PHP SDK, so I cannot tell you...nor do I have the time to go researching it.

    However, I can tell you that you should remove the limit and offset from the query. And that $fbData will probably be some sort of object or multidimensional array. Use var_dump() on it to find out.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    It is an array...

    Code:
    <?php
        require('facebook.php');
        $config = array(
            'appId' => 'MYAPPID',
            'secret' => 'MYSECRETID',
            'cookie' => true
        );
        $facebook = new Facebook($config);
        $query = urlencode('SELECT count(uid) from group_member WHERE gid = MYGROUPID limit 500 offset 500');
        try {
            $fbData = $facebook->api("/fql?q={$query}");
        } catch (FacebookApiException $e) {
            $fbData
    		 = $e->getResult();
        };
      var_dump($fbData);
    ?>
    Last edited by Mad_Griffith; May 18th, 2012 at 05:57 AM.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    You still haven't removed the limit or offset. Plus, you have two variables of $fbData...so you cannot tell whether there is an error in the try statement or not. See what the following does.

    PHP Code:
    <?php
        
    require('facebook.php');
        
    $config = array(
            
    'appId' => '350224611710644',
            
    'secret' => 'a604150d3b8184002d1f04448724d17c',
            
    'cookie' => true
        
    );
        
    $facebook = new Facebook($config);
        
    $query urlencode("SELECT count(uid) FROM group_member WHERE gid = 457030854323270");
        try {
            
    $fbData $facebook->api("/fql?q={$query}");
            
    var_dump($fbData);
        } catch (
    FacebookApiException $e) {
            echo 
    'Error occurred:<br />';
            
    var_dump($e->getResult());
        };
    ?>
    Last edited by PeejAvery; May 15th, 2012 at 02:55 PM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    I've updated the file (added a semicolon before "var_dump")
    Last edited by Mad_Griffith; May 18th, 2012 at 06:00 AM.

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    It's telling you that the authentication you're using isn't correct. Double check your app ID and secret.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    Quote Originally Posted by PeejAvery View Post
    It's telling you that the authentication you're using isn't correct. Double check your app ID and secret.
    Done it. The data are right. o_O

  12. #12
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    For some reason Facebook must not like the count() functionality in SQL. Instead, you have to count the returned results.

    PHP Code:
    <?php
      
    require_once('facebook.php');
      
    $config = array(
        
    'appId' => '350224611710644',
        
    'secret' => 'a604150d3b8184002d1f04448724d17c',
        
    'cookie' => true
      
    );
      
    $facebook = new Facebook($config);
      
    $query urlencode("SELECT uid FROM group_member WHERE gid = 457030854323270");
      try {
        
    $fbData $facebook->api("/fql?q={$query}");
        echo 
    count($fbData['data']);
      } catch (
    FacebookApiException $e) {
        echo 
    'Error occurred:<br />';
        
    var_dump($e->getResult());
      };
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  13. #13
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    Quote Originally Posted by PeejAvery View Post
    For some reason Facebook must not like the count() functionality in SQL. Instead, you have to count the returned results.

    PHP Code:
    <?php
      
    require_once('facebook.php');
      
    $config = array(
        
    'appId' => '350224611710644',
        
    'secret' => 'a604150d3b8184002d1f04448724d17c',
        
    'cookie' => true
      
    );
      
    $facebook = new Facebook($config);
      
    $query urlencode("SELECT uid FROM group_member WHERE gid = 457030854323270");
      try {
        
    $fbData $facebook->api("/fql?q={$query}");
        echo 
    count($fbData['data']);
      } catch (
    FacebookApiException $e) {
        echo 
    'Error occurred:<br />';
        
    var_dump($e->getResult());
      };
    ?>
    It works. How is that FB API?

    Thanks a lot again.
    Last edited by Mad_Griffith; May 18th, 2012 at 06:01 AM.

  14. #14
    Join Date
    May 2002
    Posts
    10,943

    Re: Total number of Facebook group members

    Not hard for a PHP developer. It's just that I had to go through and download the Facebook PHP SDK as well as check documentation to see how their FQL queries work.

    Were it just plain PHP...that would not be an issue. But the moment questions appear in the forum that pertain to 3rd party libraries...then we developers have to study those 3rd party libraries first before we can answer questions. Sometimes we have the time to do that...sometimes we do not.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  15. #15
    Join Date
    May 2012
    Posts
    13

    Re: Total number of Facebook group members

    I have updated my code

    Code:
    <div>
      <?php
      require_once('<?php bloginfo(\'template_directory\'); ?>/fb_api/facebook.php');
      $config = array(
        'appId' => 'MYAPPID',
        'secret' => 'MYSECRETID',
        'cookie' => true
      );
      $facebook = new Facebook($config);
      $query = urlencode("SELECT uid FROM group_member WHERE gid = MYGROUPID");
      try {
        $fbData = $facebook->api("/fql?q={$query}");
        echo count($fbData['data']);
      } catch (FacebookApiException $e) {
        echo 'Errore:<br />';
        var_dump($e->getResult());
      };
    
    ?>
    </div>
    now the error shown are these:

    Warning: require_once(<?php bloginfo('template_directory'); ?>/fb_api/facebook.php) [function.require-once]: failed to open stream: No such file or directory in /home/zardmediagroup/wp-content/plugins/advanced-text-widget/advancedtext.php(79) : eval()'d code on line 3

    Fatal error: require_once() [function.require]: Failed opening required '<?php bloginfo('template_directory'); ?>/fb_api/facebook.php' (include_path='.:/usr/share/php5:/usr/share/php') in /home/zardmediagroup/wp-content/plugins/advanced-text-widget/advancedtext.php(79) : eval()'d code on line 3
    Last edited by Mad_Griffith; May 18th, 2012 at 05:58 AM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured