How to get user profile using Facebook SDK and PHP?
Facebook Graph APIs are used heavily among facebook developers in the web or social networking world. This is totally HTTP based protocols which help in getting or posting data, uploading photos, videos, sending group requests around social graphs. The Facebook SDK helps in providing wonderful features for enhancing user interfaces with FaceBook data.
- Developing web pages with a Facebook login integration facility.
- Simple registration process enabling more users to the website.
- PHP5 and above
- Enable mbstring extension in “php.ini” file by uncommenting the line
Facebook SDK downloads link:
Please download the following link and save it into your working folder to include required files or libraries in your PHP code. The PHP Facebook SDK is very easy to implement and allows access to to facebook graph APIs for developers.
Steps to create FaceBook App:
- Please go to link to create APP ID and APP SECRET KEY and make
a note of it to use in the PHP code.
- Create new app by clicking Add New App. Enter all the required details like name, email id and click on Create APP ID to get APP ID and APP SECRET to access the Facebook API. You have to change some basic settings to get the desired keys. Refer the image shown below.
- Get the user access token from the link for that particular app. Refer the image below. Use your own APP_ID in the link.
The following image shows the snapshot for APP ID and APP SECRET KEY.
The following image shows the snapshot for User Access token.
PHP code: The following example code demonstrates, how to access current user name and print it using FaceBook SDK and Graph API using PHP.
Output: The FaceBook user name is printed in the following output text “User name”.
Logged in as (username) : "User name"