Sunday, November 25, 2012

Facebook PHP Tutorials(Application)How to get Female/Male friends list separately using PHP for Facebook application

Facebook is a good platform to make funny Applications.We can use PHP,Javascript and Ruby and other languages make Facebook applications.In our case we use PHP , for making simple application PHP is best and easy.PHP is similar to C and C++ , almost all functions like while ,switch ,for ,if are also available in PHP. So we can make any application using PHP.Here we are going to give some tutorials to separate Girls (Female) and Boys ( Male) friend from user . We use multiple array for separating them.

 /* Friends data collection  start here*/

$user_friends=$facebook->api('/me/friends?list_type=family',array('fields' => 'id,name,gender,username,first_name','access_token'=>$accessToken));

//We create a array to store female friends name,id,username and gender.

$select_femaleid = array(
                                                  "name" =>array(),
                                                       "id" =>array(),
                                            "username" =>array(),

//We create array for male friends
  $select_maleid = array(
                   "name" =>array(),
                        "id" =>array(),
             "username" =>array(),

//foreach property collect all data
//if and else if check gender and stores in a separate arrays

foreach ($user_friends as $friends) {
  foreach ($friends as $facebook_close) {

else if($facebook_close['gender']=='male'){



//  rand  is used to select random numbers.For example rand(1,10) will any number range from 1-10 it may be 3 or 5,9 or any number betweebn1 and 10.$female_count count all female friends and $female_rand this variable store numberof female friends.

//End of codes

//Starting of storing images and other process 

$friend_image = file_get_contents(''.$select_femaleid[$female_rand]['username'].'/picture?type=large'); // sets $image to the contents of the url
                             $file = dirname(__file__). "/user_friend/" . $select_femaleid[$female_rand]['id']. ".jpg";
                            file_put_contents($file, $friend_image);

//$select_femaleid[number][data] -=It is a multidimentional array.In C language we use two pointer to point out a data.
for example  in c 

table [2][3]={{1,2,3},{4,5,6}}

it become  1  2  3
                4  5  6
table[0][1] will gibe 0th row and 1th column , answer is 2 
same way we use our PHP code first it select number row and then to data Female/Male number is stored in number array , first it select any number ( one of friends ) then to data.Same way we can access all details like name,usernmae,gender etc...

Get 10-50% offer on all purchace - Flipkart offer zone


MM Enterprises said...

This is very deep technic, good info.

Deepak said...

i was founding this type of script and finally i got it in your site.
thanks for this post.


Copyright @ 2013 7CHIP.

Designed by Templateify & Sponsored By Twigplay