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.

0 0 vote
Article Rating
Subscribe
Notify of
guest
48 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
shaleehnet
shaleehnet
6 years ago

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

Sam KaNghoshi Naholo
Sam KaNghoshi Naholo
6 years ago

thanx so much

Gustavo Vedana Erckmann
Gustavo Vedana Erckmann
6 years ago

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

arjun
6 years ago

Thanks , changed:)

prakash
prakash
5 years ago

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

$this->load->library(‘facebook’);

arjun
5 years ago
Reply to  prakash

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

prakash
prakash
5 years ago

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

arjun
5 years ago
Reply to  prakash

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

arjun
5 years ago
Reply to  arjun

if you still need help let me know

prakash
prakash
5 years ago

please tell me

arjun
5 years ago
Reply to  prakash

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

prakash
prakash
5 years ago

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?

arjun
5 years ago
Reply to  prakash

yes, correct. your are on which ci version?

prakash
prakash
5 years ago

now
download Codeigniter Facebook SDK library, to download click here – See
more at:
http://arjunphp.com/facebook-api-codeigniter/#sthash.TPPo2B9M.dpuf
now
download Codeigniter Facebook SDK library, to download click here – See
more at:
http://arjunphp.com/facebook-api-codeigniter/#sthash.TPPo2B9M.dpuf

prakash
prakash
5 years ago

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

prakash
prakash
5 years ago

i changed but did not get output empty screen will come

arjun
5 years ago
Reply to  prakash

access /index.php/welcome/login screen

prakash
prakash
5 years ago

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

prakash
prakash
5 years ago

please tell me g

prakash
prakash
5 years ago

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

prakash
prakash
5 years ago

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
prakash
5 years ago

after login i got this error

arjun
5 years ago
Reply to  prakash

in localhost it will not work

freddy
freddy
5 years ago
Reply to  arjun

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

prakash
prakash
5 years ago

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
prakash
5 years ago

please tell me quick

prakash
prakash
5 years ago

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

prakash
prakash
5 years ago

how to solve this problem tell me

prakash
prakash
5 years ago

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
prakash
5 years ago

i waiting for your answer

prakash
prakash
5 years ago

https://uploads.disquscdn.com/images/d0600229b611ef27bc4d84867b878da85321d7f6867d2e3415ba1568acb938b7.png

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

prakash
prakash
5 years ago

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

but i did not get

El Bachir Argoub
El Bachir Argoub
5 years ago

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

arjun
5 years ago

what is the response for above line?

El Bachir Argoub
El Bachir Argoub
5 years ago
Reply to  arjun

picture

sarojkumar
5 years ago

HI

I tried this one but only i got name and id

But how to get email and other information

Please reply me

arjun
4 years ago
Reply to  sarojkumar

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
Payer Centavos
4 years ago
Reply to  arjun

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
Sangeeta
3 years ago
Reply to  arjun

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

arjun
3 years ago
Reply to  Sangeeta

enable CURL PHP extension in your server.

lalit deshmukh
lalit deshmukh
4 years ago

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
lalit deshmukh
4 years ago

I tried this one but only i got

Bilal Sheikh
Bilal Sheikh
4 years ago

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
Sidhi Gupta
4 years ago

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
Boy Abdullah
3 years ago

did u have must to install database before?

Hiten Pingolia
Hiten Pingolia
3 years ago

hello sir…
how to facebook page like using php script..

DMCA.com Protection Status
48
0
Would love your thoughts, please comment.x
()
x