• Get Friends List Using Facebook API With PHP Script

    This article describes how to get your Facebook Friends list using a PHP script. Basically this articles tells you how to retrieve your Facebook Friends list and this application also calculates the total number of your Facebook Friends. To do that, use the following procedure.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    
    Step 1
     
    Go to https://developers.facebook.com/apps, and click on "Create New Application" that is at the right site.
     
    Step 2
     
    After clicking on the Continue button, the new Captcha dialog box will be opened. Fill it in and click on the "Continue" button.
     
    Step 3
     
    After clicking on the Continue button, your app id and secret has been generated.
     
    Step 4
     
    After Step 3, enter the name of the website that you want to share the messages and links of. You can also write the localhost (the id of your application that runs on the local server) with your PHP application name.
     
    Step 5
    After the completion of all these steps, download:
    facebook-php-sdk-master.
     
    Step 6
     
    Now let's start working with the PHP script.<!--?php 
     
        //facebook application configuration
     
        $fbconfig['appid' ] = "write app id here";
     
        $fbconfig['secret'] = "write app secret here";
     
        try{
     
            include_once ('.\facebook-php-sdk-master\src\facebook.php');
     
        }
     
        catch(Exception $o){
     
            print_r($o);
     
        }
     
        $facebook = new Facebook(array(
     
          'appId'  =-->$fbconfig['appid'],
     
          'secret' =&gt; $fbconfig['secret'],
     
          'cookie' =&gt; true,
     
        ));
     
        $user       = $facebook-&gt;getUser();
     
        $loginUrl   = $facebook-&gt;getLoginUrl(
     
                array(
     
                    'scope'         =&gt; 'email'
     
                )
     
        );
     
        if ($user) {
     
          try {
     
            $user_profile = $facebook-&gt;api('/me');
     
            $user_friends = $facebook-&gt;api('/me/friends');
     
            $access_token = $facebook-&gt;getAccessToken();
     
          } catch (FacebookApiException $e) {
     
            d($e); 
     
            $user = null;
     
          }
     
        }
     
        if (!$user) {
     
            echo "<script type="text/javascript">// <![CDATA[
    top.location.href = '$loginUrl';
    // ]]></script>"; exit; } $total_friends = count($user_friends['data']); echo 'Total friends: '.$total_friends.'.'; $start = 0; while ($start &lt; $total_friends) { echo $user_friends['data'][$start]['name']; echo ''; $start++; } ?&gt;
    Tags:

Comments on this post

Leave a Reply

  • Security Code :


    5 − = four