Facebook PHP SDK Tutorial – Get Email and Profile Pic

Hello friends, on the last Facebook PHP SDK Tutorial we have created a simple login app. In this Facebook PHP SDK Tutorial we will do some more interesting things. We will get the email, username and the profile pic from the facebook account. So lets get into it.

Setting UP Things for Facebook PHP SDK Tutorial

  • We have already done this but if you haven’t read the last tutorial you should check it from the link below.

Facebook PHP SDK Tutorial – Part 1

  • So lets move ahead.

Designing Your HTML with CSS

  • In this part of Facebook PHP SDK Tutorial we will try to make our layout looks good, So we will do some CSS as well.
  • Here is my CSS Code.

Using Session to Check a User is Logged in Or Not

  • If the user is logged in successful we will set a session, so that we don’t need to login everytime.

  • Now at the top we will check, if the session is already set. If the session is already set we will initialize our session so we do not need to login again.

  • Now we will create a logout link.

  • On logout we will unset the session.

  • We will be accessing the birthday and email of the user this time, so we need to set permission.
  • On getLoginUrl we will pass an array as argument.

  • Finally we will get the user information

  • We have all the details now.
  • So we only need to display the details in our page.

  • We will also create a logout button with the URL we already defined.

  • Thats it, you can see the final code for our index.php below

  • Try running your project.
  • Bravo! Its working, so thats it for this Facebook PHP SDK Tutorial friends. Comment if having any confusions or troubles. Thank You 🙂
  • You can also download the source code of this Facebook PHP SDK Tutorial from the link given below.

[easy_media_download url=”https://dl.dropboxusercontent.com/s/kmbcm7zpfzqwe2f/Facebook-PHP-SDK-Tutorial.zip?dl=0″ text=”Download Source”]

6 thoughts on “Facebook PHP SDK Tutorial – Get Email and Profile Pic”

  1. I’m getting profile pic and full name..,
    But I’m not getting the email_id…
    What to do? help me for this…
    Thanks in advance

    Reply
  2. Hey, Thank you so much for sharing this. I ma getting Name, id and profile picture but not email and dob and gender.
    Can u please help me out with this.

    Thanks U.

    Reply
    • Hey, Thank you so much for sharing this. I ma getting Name, id and profile picture but not email and dob and gender.
      Can u please help me out with this.

      Reply

Leave a Comment