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 Facebook.com/developers 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.

48 Comments

  1. 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?

  2. 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
    C:xampphtdocsfb-ciapplicationlibrariesbase_facebook.php:19
    Stack trace:
    #0 C:xampphtdocsfb-ciapplicationlibrariesfacebook.php(18):
    require_once()
    #1 C:xampphtdocsfb-cisystemcoreLoader.php(973):
    include_once(‘C:xampphtdocs…’)
    #2 C:xampphtdocsfb-cisystemcoreLoader.php(216):
    CI_Loader->_ci_load_class(‘facebook’, NULL, NULL)
    #3 C:xampphtdocsfb-ciapplicationcontrollerswelcome.php(14):
    CI_Loader->library(‘facebook’)
    #4 [internal function]: Welcome->login()
    #5 C:xampphtdocsfb-cisystemcoreCodeIgniter.php(359):
    call_user_func_array(Array, Array)
    #6 C:xampphtdocsfb-ciindex.php(202):
    require_once(‘C:xampphtdocs…’)
    #7 {main}
    thrown in C:xampphtdocsfb-ciapplicationlibrariesbase_facebook.php on line 19

    please tell solution

  3. 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

  4. 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)

  5. 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

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

    but i did not get

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

    1. 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’));

      1. 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.

      2. 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

  8. 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

  9. 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….

  10. 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

Leave a Reply

Your email address will not be published.