A PHP Class For Facebook Application Developer

Posted: March 20th, 2009 | Author: admin | Filed under: facebook, php | Tags: , , , , , , | 15 Comments »

You know facebook is a great social application for million of users. And to develop a application for this site is also very popular. So I have planned to write a class where facebook application developer can do most of the basic things for their application using this class.Specially thanks to emran bhai and anis to review my class.The basic feature of this class

  • Get Facebook Users profile information
  • Get Friend list of a facebook user
  • Send Notification to Facebook user
  • Send Email Notification to Facebook user
  • Set Your Application at Facebook user profile page
  • Publish News feed to Facebook user

You can do above all the things to use this Class.

Download

You can download it from here. The zip file contains this class along with an example. You can also find full documentation here.

You can also download it from phpclasses.org

How to use it

   1: // Include our files
   2: include_once ('FBToolbox.class.php');
   3:
   4: // Prepare the object
   5: $fbToolboxObj = new FBToolbox('YOUR_API_KEY', 'YOUR_SECRET_KEY');
   6:
   7:
   8: // Get user information
   9: $userInfo = $fbToolboxObj->getUserInfo('FB USER ID');
  10: //print_r($userInfo);
  11: echo $userInfo[0]['current_location']['city'];
  12:
  13: // Get friend list here
  14: $friendList = $fbToolboxObj->getFriendList('FB USER ID',false,0,20);
  15: //print_r($friendList);
  16:
  17: // Send notification
  18: $fbToolboxObj->sendNotification(array('FB USER ID'),'test api class','app_to_user');
  19:
  20: // Send email notification (CAUTION: your application must have permission from user)
  21:
  22: $fbToolboxObj->sendEmail('FB USER ID','test api class','test api class');
  23:
  24: // Publish news feed
  25:
  26:
  27: $one_line_story_templates[] = '{*actor*} has developed a php wrapper 
  28: class for facebook application developer.';
  29: //You have to run this function only one times to get template bundle id
  30: $templateBundleId = $fbToolboxObj->getTemplateBundleId($one_line_story_templates);
  31:
  32: $fbToolboxObj->publishNewsFeed('FB USER ID',$templateBundleId);
  33:
  34: // Add your application to your profile
  35: $fbToolboxObj->addToProfile('FB USER ID',"Wider FbMl","narrow fbml");
  36: ?>
  37:
  38: <!-- you have to print this line to add application to user profile
  39: if user click on addtoprofile link then above function will work -->
  40: <div class="section_button"><fb:add-section-button section="profile"/></div>
  41:

So devs this is all about my php class. In my next post I will show you how to develop a facebook application with new platform in details using this class. Enjoy!!!!

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

15 Comments on “A PHP Class For Facebook Application Developer”

  1. 1 Karen UNITED STATES said at 2:56 pm on March 20th, 2009:

    Wow, that

  2. 2 pete UNITED KINGDOM said at 1:50 am on March 23rd, 2009:

    I like this class, how do you adapt it as a buddpress plugin?

    buddypress site.

    http://www.buddypress.org

  3. 3 shree NEPAL said at 7:56 am on March 23rd, 2009:

    hi
    i know about this facebook class but can you explain more how to use this class in my application

  4. 4 Billy UNITED KINGDOM said at 1:33 pm on March 24th, 2009:

    Hey,

    wow this class sounds amazing. Do you have any more info on how to implement it?

    Billy?

  5. 5 ehsan PAKISTAN said at 6:10 am on April 10th, 2009:

    hi

    can we send email to facebook users on facebook via facebook connect

    thanks

  6. 6 Una classe PHP per creare applicazioni Facebook | BigThink UNITED STATES said at 4:16 am on April 17th, 2009:

    [...] tratta di Facebook Toolbox, che incorpora in semplici metodi tutte le chiamate e le varie operazioni che possono tornarci [...]

  7. 7 ehsan PAKISTAN said at 8:34 am on April 28th, 2009:

    hi

    Can u help to send invitation to facebook user like multi-selector invitation

  8. 8 admin BANGLADESH said at 12:05 pm on April 28th, 2009:

    @ehsan
    thanks to give time here.
    I am writting another one post
    about facebook application.
    so please stay with me.
    thanks
    raju

  9. 9 ehsan PAKISTAN said at 9:56 pm on June 12th, 2009:

    hi

    i mean when we like to send invitation to more then one friends in facebook we use multiselect option , now i like to send invitation like that but i want to send invitaion by using my own database , its possible to that with facebook or not ,

    if yes then how

    thanks

  10. 10 Ayan Debnath INDIA said at 7:05 am on June 24th, 2009:

    I am facing one small problem/error -

    “Fatal error: Uncaught exception ‘FacebookRestClientException’ with message ‘Session key invalid or no longer valid: ‘ in /home/gigahert/public_html/test/facebook/client/facebookapi_php5_restlib.php:2977 Stack trace: #0 /home/gigahert/public_html/test/facebook/client/facebookapi_php5_restlib.php(946): FacebookRestClient->call_method(‘facebook.fql.qu…’, Array) #1 /home/gigahert/public_html/test/facebook/FBToolbox.class.php(126): FacebookRestClient->fql_query(‘SELECT uid FROM…’) #2 /home/gigahert/public_html/test/facebook/FBToolbox.class.php(227): FbToolbox->getFriendList(’1015601512′, true) #3 /home/gigahert/public_html/test/facebook/1.php(52): FbToolbox->publishNewsFeed(’1015601512′, ’115329175943′) #4 {main} thrown in /home/gigahert/public_html/test/facebook/client/facebookapi_php5_restlib.php on line 2977″

    Can you pls suggest me to solve it ?

  11. 11 Jayanthi INDIA said at 12:33 am on July 25th, 2009:

    Use try catch block for your script as like,

    try{
    if(count($facebook->api_client->friends_get())>0){

    — your script here—

    }catch (Exception $ex) {
    $facebook->set_user(null,null);
    }

    I hope that the above script will help you.

  12. 12 3 Clases PHP para desarrollar aplicaciones para Facebook | pixelco.us blog UNITED STATES said at 4:12 pm on August 5th, 2009:

    [...] Web: http://www.stylephp.com/2009/03/20/a-php-class-for-facebook-application-developer [...]

  13. 13 19 Recursos para potenciar desarrollos con PHP | pixelco.us blog UNITED STATES said at 4:47 pm on August 12th, 2009:

    [...] A PHP Class For Facebook Application Developer [...]

  14. 14 Using APIs With PHP? Here Are Your Classes | Jeez Tech said at 12:04 pm on November 23rd, 2009:

    [...] Facebook Application Developer [...]

  15. 15 Classes PHP pour API FRANCE said at 4:17 am on November 24th, 2009:

    [...] Facebook Application Developer [...]


Leave a Reply