Welcome Guest, Not a member yet? Register   Sign In
Facebook Graph API and Open Graph package
#1

[eluser]chrisnharvey[/eluser]
Hello,

I've been working on a Facebook package for a few days now and I thought I'd post it here so you can check it out.

Currently it consists of a library, a helper and a config file. It also includes a sample controller and view.

The documentation for this library is located in the facebook_demo view and the it is as simple as:
Code:
$this->facebook->call("get", "me");
to call call the Facebook Graph API, and as simple as:
Code:
$this->facebook->call("post", "me/feed", array("message" => "This is a message from the CodeIgniter Facebook Package"));
to POST or GET parameters to the Graph API. It also supports the uploading of media to Facebook like this:
Code:
$image = "@".realpath(BASEPATH."../image.jpg"); // This locates a JPEG located in the root directory of your CodeIgniter setup (where your index.php file is located)
$this->facebook->call("post", "me/photos", array("source" => $image, "message" => "This is an image uploaded from the CodeIgniter Facebook Package"));

You can also easily add Open Graph meta tags to your view files by creating an array like this:
Code:
$data['meta'] = array("og:title" => "CodeIgniter Facebook Library", "og:type" => "website", "og:description" => "A Facebook library for CodeIgniter that allows you to make calls to the Facebook Graph API and easily integrate the meta tags for the Open Graph protocol.", "fb:app_id" => $this->config->item("facebook_app_id"));
$this->load->view('facebook_demo', $data);
and parse the array into meta tags in your view by placing this line of code in the <head> of your HTML:
Code:
<?=facebook_meta($meta)?>


The best way to keep this package up-to-date is to create a "b2tm" folder inside your "third_party" folder, with a "facebook" folder in there with the contents of the entire package, you can then replace the code when a new release is available, either through "git pull" or simply copy the updated files into there. You can then add the package path using:
Code:
$this->load->add_package_path(APPPATH.'third_party/b2tm/facebook/application');


You can download this package from this GitHub repository: https://github.com/b2tm/CodeIgniter-Facebook-Package
Please let me know if you find any bugs or would like to request any features.

Hope you like it! Smile
#2

[eluser]RaBu[/eluser]
is this working with the newest version of Codeigniter 2.0.2?

I have just downloaded and tasted it, but can't get it to work Sad Any help/input is appreciated Smile
#3

[eluser]chrisnharvey[/eluser]
Hello,

I'm currently using it on 2.0.2 and it seems to work for me. May I ask if you get any error messages or what happens when you try to use it?

Thanks,

- Chris
#4

[eluser]chrisnharvey[/eluser]
Hi,

I just did some more debugging of the code and I believe that I have fixed the problem with the latest commit to the GitHub repository https://github.com/b2tm/CodeIgniter-Facebook-Package.

I believe the problem was when calling the Facebook API cURL could not verify the SSL certificate so did not complete the call to the API. I have disabled checking of the SSL certificate in cURL and the CodeIgniter package should now work for you.

Please download the latest source code from the GitHub repository and try again.

My apologies for the inconvenience, please let me know if this solved your issue or if you have any more problems.

Thanks,

- Chris
#5

[eluser]appleboy[/eluser]
Hi all,

everybody can refer the following tutorial, it is working now.

PHP SDK 3.0 & Graph API base Facebook Connect Tutorial

http://thinkdiff.net/facebook-connect/ph...-tutorial/

Facebook PHP SDK and CodeIgniter for basic user authentication

http://www.dannyherran.com/2011/02/faceb...ntication/
#6

[eluser]RaBu[/eluser]
Thanks Chris, and thanks for your quick reply - I will try with your updated code Smile
#7

[eluser]RaBu[/eluser]
Hi Chris,

Thanks I have it working now. But I have two issues relating to login:

1.: the "Login using JavaScript & XFBML" part is not working, it seams like facebook_scope() is returning nothing...

2.: if I use the "Login without using JavaScript & XFBML" part, using the $this->facebook->login_url() - I can login and gets redirecte back, but when redirected back - the page doesn't reload and pick me up as logged in on facebook, so I still see the login buttons, but if I manually reload, then it picks it up.

All the best,
Rasmus
#8

[eluser]RaBu[/eluser]
hi again Chris,

I have looked into it and it looks like you need to add some additional cleaning up stuff to your logout() function, I have modified mine to look like this:

Code:
setcookie("fbs_".$this->_app_id, "", time()-3600); //delete the cookie
    $this->_unset("facebook_access_token");
    $this->_CI->session->sess_destroy(); //kill the session

Hope you can use it Smile

- Rasmus
#9

[eluser]Keylocker[/eluser]
For me the login works but I have two questions:

1) How can I get some of the user data and store them in my database? (Name, Surname, email, etc)
2) Can't figure out how to logout a user

Many thanks.
Mike




Theme © iAndrew 2016 - Forum software by © MyBB