Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the total number of friends using the Facebook API and PHP?

Tags:

php

facebook

api

How can I get the total number of friends using the Facebook PHP API?

This is my code so far:

<?php require_once 'facebook.php'; 
  $appapikey = 'x'; 
  $appsecret = 'x'; 
  $facebook = new Facebook($appapikey, $appsecret);
  $user_id = $facebook->getuser(); $friends = ???; 
like image 390
conqrr Avatar asked Dec 12 '22 17:12

conqrr


1 Answers

Try this

$uid = $facebook->getUser();  
$fbme= $facebook->api('/me');  
echo "Welcome ".$fbme['name'];  
$frnz= $facebook->api('/me/friends');  
echo "< br />Total Number of friends you have:".sizeof($frnz['data'])."< br/>";  
like image 179
Sandiip Patil Avatar answered May 14 '23 15:05

Sandiip Patil