Fbtt Facebooker Tutorial

Next Lesson → Make User Login

1.1) Getting Started


The purpose of this tutorial is to explain many aspects of the Facebooker project. The general approach here is provide running live code to be used as a reference for you own implementation. All the code samples in this tutorial are from the actual live code running the application. The facebooker plugin is pulled in as an external as well so the tutorial should be up to date with the latest code.

  1. Create a rails application:

    rails facebooker_tutorial

  2. Install Facebooker Plugin:

    script/plugin install git://github.com/mmangino/facebooker.git or

    cd RAILS_ROOT/vendor/plugins; git clone git://github.com/mmangino/facebooker.git or

    Grab the tarball from http://github.com/mmangino/facebooker/tree/master and stick it in vendor/plugins manually

  3. Create a controller:

    ruby script/generate controller getting_started

  4. Setup your application on Facebook.

    This should take you to the new app page. Add_application

    • Enter in Your Application Name. This name will appear anywhere your application mentioned.
    • Enter in you Callback URL. Make this the base URL of your server. Note: For FBML apps, like this one, the url must be web accessible.
    • Enter in your Canvas Page URL. This will be the path that users see in their browser.

  5. Setup facebooker environment via RAILS_ROOT/config/facebooker.yml, You can copy the template file from the facebooker source.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    
    # File: config/facebooker-mock.yml
    # The api key, secret key, and canvas page name are required to get started
    # Tunnel configuration is only needed if you are going to use the facebooker:tunnel Rake tasks
    # Your callback url in Facebook should be set to http://public_host:public_port
    
    development:
     api_key: 442c6504bd2362d8a7fba7303cd583ca 
     secret_key: XXXXXXXXXXXXX
     canvas_page_name: facebooker_tutorial    
     callback_url: http://staging.travelerstable.com:8888
     tunnel:
         public_host_username: fooberryfoo 
         public_host: staging.travelerstable.com
         public_port: 8888
         local_port: 3000    
    test:
      api_key: 
      secret_key: 
      canvas_page_name: 
      tunnel:
        public_host_username: 
        public_host: 
        public_port: 4007
        local_port: 3000
    production:
      api_key: 
      secret_key: 
      canvas_page_name: 
      tunnel:
        public_host_username: 
        public_host: 
        public_port: 4007
        local_port: 3000 
    
    • Enter in the callback url that you specified in the facebook application settings.
    • Enter in your Canvas Page Name. This the last part of the path you entered in the Canvas Page URL
  6. Okay create a view for you getting_started controller. And put anything you want in there.

    EDIT: app/views/getting_started/add_facebook_application.fbml.erb. Like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    
    # File: app/views/getting_started/_steps.html.erb
    <div id="tutorial_steps">
    
    
    <ol>
    <li> Create a rails application: <p class="command_line"> rails facebooker_tutorial</p></li>    
    <li> Install Facebooker Plugin: <p class="command_line"> script/plugin install git://github.com/mmangino/facebooker.git or </p>
     <p> cd RAILS_ROOT/vendor/plugins; git clone git://github.com/mmangino/facebooker.git or </p>
                 <p>    Grab the tarball from <%= link_to("http://github.com/mmangino/facebooker/tree/master", "http://github.com/mmangino/facebooker/tree/master") %> and stick it in vendor/plugins manually
    </p></li>
    
    <li> Create a controller:        <p class="command_line"> ruby script/generate controller getting_started</p></li>
    
    
    <li>
            Setup your application on <%= link_to("Facebook", "http://www.facebook.com/developers/editapp.php?new", :target => "fb_tut_external") %>.
            <p class="descriptive_text">
                    This should take you to the new app page. 
                    <%= image_tag("getting_started/add_application.jpg") %> 
                    <ul>     
                            <li> Enter in Your Application Name.  This name will appear anywhere your application mentioned. </li>
                            <li> Enter in you Callback URL.  Make this the base URL of your server. <em> Note: For FBML apps, like this one, the url must be web accessible.</em></li>
                            <li> Enter in your Canvas Page URL.  This will be the path that users see in their browser. </li>
                    </ul>
            </p>        
                
    </li>
    <li>
            Setup facebooker environment via RAILS_ROOT/config/facebooker.yml, <em> You can copy the template file from the facebooker source.</em> 
            <div style="width:90%;margin: 10px auto;"> 
        <%= highlight_file("config/facebooker-mock.yml") %>
    </div>  
        <ul> 
               <li>Enter in the callback url that you specified in the facebook application settings.</li>
               <li>Enter in your Canvas Page Name. <em>This the last part of the path you entered in the Canvas Page URL </em></li> 
            </ul>
    
    </li>
    <li>Okay create a view for you getting_started controller.  And put anything you want in there.
        <p>EDIT: app/views/getting_started/add_facebook_application.fbml.erb.  Like this: </p>
        <%= highlight_file("app/views/getting_started/_steps.html.erb") %>
        </li>
    <li> 
            Add a default route for your application.  
            <div style="width:90%;margin: 10px auto;"> 
            
            <%= highlight_code("map.connect '', :controller => 'getting_started', :action => 'add_facebook_application'") %>
            </div>
    </li>
    <li>
            Start up rails <p class="command_line">ruby script/server  </p>
    </li>
    <li>
            Check out your app at <%= link_to(url =  url_for(:controller =>  params[:controller ], :action => params[:action], :only_path => false), url  ) %>
    </li>
    
    <li>Now create a view accessible straight from the web and put whatever you want in there. <p>EDIT: app/views/getting_started/add_facebook_application.html.erb</p></li>
    <li> Try from the web <%= link_to(url =  url_for(:controller =>  params[:controller ], :action => params[:action], :canvas => false, :only_path => false), url  ) %>  -- Here you are accessing you app straight from the web!!</li>     
    
    </ol>            
    
    </div> 
    
    
  7. Add a default route for your application.
    
    
    map.connect '', :controller => 'getting_started', :action => 'add_facebook_application'
  8. Start up rails

    ruby script/server

  9. Check out your app at http://apps.new.facebook.com/facebooker_tutorial/
  10. Now create a view accessible straight from the web and put whatever you want in there.

    EDIT: app/views/getting_started/add_facebook_application.html.erb

  11. Try from the web http://fbtt.shacknet.nu/ -- Here you are accessing you app straight from the web!!
Next Lesson → Make User Login
Peepcodead

Comment Section for Getting Started

Displaying 20 of 60 posts.

Anthony wroteat 3:04pm on August 22

I figured it out using for @fbuser.friends! :first_name...FIELDS

Anthony wroteat 1:37pm on August 22

Where can I find information on how to use iframes with facebooker? I have a facebooker/rails app that makes heavy use of JQuery and prototype javascript libraries for the UI pagination and accordion effects as well as custom AJAX form validations and at the very least I would like to be able to render something similar in HTML:

<% for a_friend in @fbuser.friends %>
<%= fb_profile_pic(a_friend) %>
<%= fb_name a_friend %><br />
<% end %>

When I do this in an iFrame where I can render the user's profile photo and their human readable name. When I use @fbuser.friends!(:name) it only spits out their facebook ID and the API documentation isn't very clear on how to do this.

David wroteat 11:07pm on July 30

I want to announce that the Facebooker on Rails book has finally been released. It covers all the latest API and Design Changes. It is also based on an example app that you can grab. Check it out at http://peepcode.com/products/rails-on-facebook , it is really affordable.

David wroteat 6:51pm on July 16

Don't call your class User.. I can see how is certain contexts you would get naming collisions.

David wroteat 6:50pm on July 16

Highlight file is an internal method that I am using so you don't really need it . I reads a file in and displays it as syntax highlighted code.

Dmitry wroteat 5:51pm on July 16

Perhaps I'm experiencing all sorts of problems because I have a User model which might conflict with facebooker User model. Any suggestions how to avoid this potential collision in the best possible way?

Dmitry wroteat 5:47pm on July 16

Anybody tried to use facebooker with restful_authentication? I think these two have some sort of a conflict, would like to find out if anybody else had any problems with those.

Allen wroteat 5:35pm on July 16

Says it can't find "highlight_file" method. I realize this is not essential to get this to work, but what am I missing?

David wroteat 11:13am on July 11

This is how the tutorial code works. If the request is for a canvas page rails will attempt to render index.fbml.erb, otherwise it will render index.html.erb ... no need for a render block. If you get this working please post back and I can add something to the tutorial on custom render blocks.

Tony wroteat 1:24am on July 11

How to set the action of the getting_started_controller then? I used "format.html" and get "HTTP 406 Error" and I failed to use "format.fbml",too. Can you put more content on this part?

David wroteat 5:57pm on July 9

Okay I updated the tutorial to reference the newest repo on GIT. Don't use SVN anymore!

Dmitry wroteat 7:21pm on July 7

Nothing obvious jumps out, obviously this is a SystemStackError -- it's really hard to believe that no one else experiencing this problem. The only thing i can think of is that my application was originally on rails 2.0.1 then migrated to 2.1.0, or there are some gems that are conflicting, or something else like this. I actually spent few hours trying to resolve the gem -- nada. Any suggestions where to look next :) ?
please help

Dmitry wroteat 2:02pm on July 7

Well,
i also had a gem installed, unfortunately uninstalling the gem didn't make any difference. Where else should i look for a second copy of a plugin, there is only one facebooker under vendors/plugin folder -- i guess i'm a bit confused. Is it possible that the gem did not uninstall cleanly, is there some way to forcefully remove it?

David wroteat 12:03pm on July 7

Total long shot here... Do you have the plugin installed twice? Maybe with different names? I had this bug a couple of days ago and it was because I had two versions of facebooker installed.

Dmitry wroteat 11:03am on July 7

This is a continuation of a previous post,
I'm on rails 2.1.0,
just to eliminate any problems with particular environment, i tried facebooker plugin on two different machines -- the same exception (see previous post).
Am i making a right assumption that after installing plugin into existing app, everything should still work as it used to, or i need to make changes to the rails app too?

Dmitry wroteat 10:02am on July 7

I don't think the latest plugin from git works either,
I tried the both of the methods and when ever access any of the application urls that used to work prior to installing the plugin, get following error:
SystemStackError

stack level too deep

RAILS_ROOT: /Users/damelche/workspace/cleantogether
Application Trace | Framework Trace | Full Trace

vendor/plugins/facebooker/init.rb:25:in `inherited_without_facebooker'
vendor/plugins/facebooker/init.rb:25:in `inherited_without_facebooker'
vendor/plugins/facebooker/init.rb:25:in `inherited'
app/controllers/application.rb:11

vendor/plugins/facebooker/init.rb:25:in `inherited_without_facebooker'
vendor/plugins/facebooker/init.rb:25:in `inherited_without_facebooker'
vendor/plugins/facebooker/init.rb:25:in `inherited'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in

David wroteat 5:57pm on July 6

You have two options:

-- Install GIT on system



cd RAILS_ROOT/vendor/plugins



git clone git://github.com/mmangino/facebooker.git

OR

--- Go to http://github.com/mmangino/facebooker/tree/master

and Download the source

I also think that Rails 2.1 supports git plugins so you may be able to do a /script/plugin install git://github.com/mmangino/facebooker.git

Lee wroteat 5:26am on July 6

tried but it doesnt seem to work

Rajiv wroteat 10:34pm on July 5

@Dmitry

Try - ./script/plugin install git://github.com/mmangino/facebooker.git

Dmitry wroteat 7:39pm on July 5

As it was pointed out, the svn repo is broken, you have to install it from git instead.
Anybody has any suggestions how to install it from git?
I tried to run:
script/plugin install http://github.com/mmangino/facebooker/tree/master
and it goes into infinite loop. Maybe for someone it's obvious how to install plugin from git, but i'm fairly new to it, so some simple instructions would be much appreciated.

See all posts »