ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Facebook Graph API and Open Graph package

March 05, 2011 8:23pm

Subscribe [6]
  • #1 / Mar 05, 2011 8:23pm

    chrisnharvey

    5 posts

    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:

    $this->facebook->call("get", "me");

    to call call the Facebook Graph API, and as simple as:

    $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:

    $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:

    $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:

    <?=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:

    $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! 😊

  • #2 / Jul 20, 2011 6:54pm

    RaBu

    19 posts

    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 :( Any help/input is appreciated 😊

  • #3 / Jul 20, 2011 7:06pm

    chrisnharvey

    5 posts

    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 / Jul 20, 2011 8:13pm

    chrisnharvey

    5 posts

    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 / Jul 21, 2011 2:36am

    appleboy

    38 posts

    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/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/

    Facebook PHP SDK and CodeIgniter for basic user authentication

    http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/

  • #6 / Jul 21, 2011 5:00am

    RaBu

    19 posts

    Thanks Chris, and thanks for your quick reply - I will try with your updated code 😊

  • #7 / Jul 21, 2011 7:54pm

    RaBu

    19 posts

    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 / Jul 22, 2011 10:42am

    RaBu

    19 posts

    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:

    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 😊

    - Rasmus

  • #9 / Nov 16, 2011 5:35am

    kikz4life

    77 posts

    tried your code rabu, but still i can’t logout.

  • #10 / Dec 01, 2011 4:50am

    skillfullbus

    4 posts

    Hi Chris,
    I’m a newbie in Facebook app development. I would like to make my app using CI. While configuring your package I came accross the “facebook_default_scope” in the config file. I’m not too sure what values should I be giving here and where do I find it. Can you please help me.


    Thanks

  • #11 / Dec 01, 2011 6:15am

    appleboy

    38 posts

    Hi Chris,
    I’m a newbie in Facebook app development. I would like to make my app using CI. While configuring your package I came accross the “facebook_default_scope” in the config file. I’m not too sure what values should I be giving here and where do I find it. Can you please help me.


    Thanks

    Please referrer the following facebook developer document

    https://developers.facebook.com/docs/reference/api/permissions/

  • #12 / Dec 01, 2011 6:57am

    skillfullbus

    4 posts

    Thanks appleboy ! I’ll try that out.

  • #13 / Apr 19, 2012 5:32am

    Keylocker

    8 posts

    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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases