Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to get facebook user details using PHP?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.44k
    Comment on it

    Hello Reader's if you are looking to develop a web app which gets the facebook user profile details then by using PHP you can do this. Facebook gives us the public details of any user like: photo, cover location and birthdays. To use this you need to do some work on Graph API by Facebook. So lets get started working on it.


    Step1: First create login in as a developer

    Step2: Create new app fill all its details required and make it live.

    Step3. Create a new function in your controller name it to fb(). Its code will go like this:-

    function fb($userid)
    			$curl = curl_init();
    			$token = 'YOUR_FB_TOKEN';
    			// Set some options - we are passing in a useragent too here
    			curl_setopt_array($curl, array(
    			CURLOPT_URL => ''.$userid.'?fields=bio,education,email,gender,hometown,cover,name&access_token='.$token,
    			CURLOPT_USERAGENT => 'snooptravel via curl'
    			// Send the request & save response to $resp
    			$resp = curl_exec($curl);
    			$user_fb = json_decode($resp, 1);
    			return $user_fb;

    In the code, the request you sent is made by curl. The token is provided by the facebook. you can get this from the app page on your facebook.

    Now you need to need to add the details in parameters separate by comma. eg email, gender,homtown,bio. You can get this in detailed documentation of graph api section. 
    Then you have to put the facebook userid of any user. You get  facebook id by facebook profile url.  Now save this code and run. Facebook Graph API will return you the all of those details in json format. You only need to decode this json string and every details will be set as a key in arrays. 

    Step4: To access and use this fb () function you need to call this function and pass the user facebook id. Its code will go like this:-

    <?php 	$user_fb = $this->Mailmodel->fb($ViewPlace['FBid']); }?>

    Now print this $user_fb and the output of the function will be like this;

        [cover] => Array
                [id] => 956276541167528
                [offset_y] => 50
                [source] =>
        [name] =>  
        [id] => 100003555744237

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: