Posted on Updated on - Arjun

How to Use the Facebook API with Codeigniter

This post shows you how to get the sample Facebook application working with the CodeIgniter framework. For PHP Facebook has an PHP Facebook API and it is located on github. This library gives the php developer much more intuitive access to the facebook api methods and entities.

Download Facebook PHP API ?

To Download Facebook PHP SDK (v.3.2.3) click here
To Download Facebook PHP SDK (v.4) click here

Getting Started

So, let’s get started with your first Facebook application written with CodeIgniter. By the end of it, you’ll have everything you need to create a Facebook application.

1. Download CodeIgnier Framework and Install it. if you install currently , You should see the generic message, “Welcome to CodeIgniter!” If you don’t, you’ve missed something along the way. Reinstall CodeIgniter and start over.

2. Go to and set up a new application.

3. now download Codeigniter Facebook SDK library, to download click here

4.copy and place config and library directory in your ci app.

How do I use it?

You can load the facebook sdk like other libraries in Codeigniter , but you need to set config values in config/facebook.php , Enter your app ID and secret code there.

That’s it your done!.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.


I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.

  • shaleehnet

    but how to make automated post to my page which is administrated by me ?

  • Sam KaNghoshi Naholo

    thanx so much

  • Gustavo Vedana Erckmann

    Please fix Codeigniter Facebook SDK library link, is hhttps instead https 🙂

    • Thanks , changed:)

  • prakash

    i followed the step i called the library after what can i do help me please


    • Now you can access all of the facebook SDK methods , like print_r($this->facebook);

  • prakash

    i used print_r($this->facebook); but empty screeen will come

    • Hey , just tested downloaded files , its just working fine , access in your browser something like : http://localhost/fb-ci/index.php/welcome/login , before this add your app keys in facebook.php file which you can find at config/facebook.php

      • if you still need help let me know

  • prakash

    please tell me

    • you are not installed properly, if you install properly you should have access

  • prakash

    config, facebook .php file is inserted after base_facebook.php, facebook.php,fb_ca_chain_bundle.crt
    file is uploaded in libraries this is proper intalliation?

    • yes, correct. your are on which ci version?

  • prakash

    download Codeigniter Facebook SDK library, to download click here – See
    more at:
    download Codeigniter Facebook SDK library, to download click here – See
    more at:

  • prakash

    sorry you give the link in instruction in 3 steps i dont know the version

  • prakash

    i changed but did not get output empty screen will come

    • access /index.php/welcome/login screen

  • prakash

    index.php/welcome/login but i did not get output empty screen occur please tell me

  • prakash

    please tell me g

  • prakash

    i download your link after change ci name fb-ci
    i run http://localhost/fb-ci/index.php/welcome/login
    this error will come
    Uncaught exception ‘Exception’ with message ‘Facebook needs the CURL PHP
    extension.’ in
    Stack trace:
    #0 C:xampphtdocsfb-ciapplicationlibrariesfacebook.php(18):
    #1 C:xampphtdocsfb-cisystemcoreLoader.php(973):
    #2 C:xampphtdocsfb-cisystemcoreLoader.php(216):
    CI_Loader->_ci_load_class(‘facebook’, NULL, NULL)
    #3 C:xampphtdocsfb-ciapplicationcontrollerswelcome.php(14):
    #4 [internal function]: Welcome->login()
    #5 C:xampphtdocsfb-cisystemcoreCodeIgniter.php(359):
    call_user_func_array(Array, Array)
    #6 C:xampphtdocsfb-ciindex.php(202):
    #7 {main}
    thrown in C:xampphtdocsfb-ciapplicationlibrariesbase_facebook.php on line 19

    please tell solution

  • prakash

    login button is clicked after getting this error
    Given URL is not allowed by the Application configuration: One or more
    of the given URLs is not allowed by the App’s settings. It must match
    the Website URL or Canvas URL, or the domain must be a subdomain of one
    of the App’s domains

  • prakash

    after login i got this error

    • in localhost it will not work

      • freddy

        hi i try it in subdomain also not working ? what do i wrong here

  • prakash

    in local print_r($this->facebook); get output (loading the library when using $this->load->library(‘facebook’)

    server did not get output print_r($this->facebook) and $this->load->library(‘facebook’)(did not loading the library)

  • prakash

    please tell me quick

  • prakash

    $this->load->library(‘facebook’) library fun not load in server

  • prakash

    how to solve this problem tell me

  • prakash

    base_facebook.php, facebook.php file upload in libaries but i calling $this->load->library(‘facebook’)

    library is not work server side but work in local machine i dont know please tell me the solution

  • prakash

    i waiting for your answer

  • prakash

    hai friends i got the output but i need user another information(email etc) where i get tell me

  • prakash

    ‘scope’ => array(’email,user_birthday,user_location,user_work_history,user_hometown,user_photos’)

    but i did not get

  • El Bachir Argoub

    hello how i can use user_photos in api this is my code $user_fre = $facebook->api(‘/me/photos?limit=2&type=uploaded’);

    • what is the response for above line?

      • El Bachir Argoub


  • HI

    I tried this one but only i got name and id

    But how to get email and other information

    Please reply me

    • To fetch email address you must have the permission to access it. To request permissions, add email to the scope as shown below –

      $facebook->getLoginUrl(array(‘scope’ => ’email,read_stream’));

      • Payer Centavos

        Hi I’ve tried that but it comes with an FB error:
        Invalid Scopes: read_stream. This message is only shown to developers. Users of your app will ignore these permissions if present.

      • Sangeeta

        Hellow Sir ,

        After trying the steps i am getting Below error ,Its giving CURL erroor
        Fatal error: Uncaught exception ‘Exception’ with message ‘Facebook needs the CURL PHP extension.’ in wampwwwciprojectapplicationlibrariesbase_facebook.php on line 19
        ( ! ) Exception: Facebook needs the CURL PHP extension. in wampwwwciprojectapplicationlibrariesbase_facebook.php on line 19

        • enable CURL PHP extension in your server.

  • lalit deshmukh

    Fatal error: Uncaught exception ‘Exception’ with message ‘Facebook needs the CURL PHP extension.’ in C:xampphtdocsciapplicationlibrariesbase_facebook.php:19 Stack trace: #0 C:xampphtdocsciapplicationlibrariesfacebook.php(18): require_once() #1 C:xampphtdocscisystemcoreLoader.php(973): include_once(‘C:xampphtdocs…’) #2 C:xampphtdocscisystemcoreLoader.php(216): CI_Loader->_ci_load_class(‘facebook’, NULL, NULL) #3 C:xampphtdocsciapplicationcontrollerswelcome.php(10): CI_Loader->library(‘facebook’) #4 C:xampphtdocscisystemcoreCodeIgniter.php(308): Welcome->__construct() #5 C:xampphtdocsciindex.php(202): require_once(‘C:xampphtdocs…’) #6 {main} thrown in C:xampphtdocsciapplicationlibrariesbase_facebook.php on line 19

  • lalit deshmukh

    I tried this one but only i got

  • Bilal Sheikh

    Hi Arjun,
    How are you?
    Can you help me in get facebook data like join groups and pages likes of login user

    I am waiting for your reply….

  • Sidhi Gupta

    hlo sir i download the facebook api and get the appid and secert from facebook developer
    but when i run facebook api on localhost it show error

  • Boy Abdullah

    did u have must to install database before? Protection Status