Facebook mit Rails und Facebooker

Post on 02-Dec-2014

2.969 views 0 download

description

a rather rough version of a presentation on facebook and how to write fb-apps in rails.

Transcript of Facebook mit Rails und Facebooker

Rails vs. FacebookerFacebook-Apps mit Facebooker

Jan Krutisch <jan.krutisch@mindmatters.de>

10. Juni 2009Rails Usergroup Hamburg

Donnerstag, 11. Juni 2009

Facebook you say?

Donnerstag, 11. Juni 2009

200 Gazillionen Benutzer

Donnerstag, 11. Juni 2009

(pro Tag)

Donnerstag, 11. Juni 2009

(ungefähr)

Donnerstag, 11. Juni 2009

verdammt viele

Donnerstag, 11. Juni 2009

potentielle Kunden

Donnerstag, 11. Juni 2009

für was?

Donnerstag, 11. Juni 2009

for great justice

Donnerstag, 11. Juni 2009

Step 3: Profit

Donnerstag, 11. Juni 2009

Virales Wachstum und so...

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

Glaubt mir!

Donnerstag, 11. Juni 2009

anyway

Donnerstag, 11. Juni 2009

facebook application?

Donnerstag, 11. Juni 2009

Integrationspunkte

Donnerstag, 11. Juni 2009

Canvas

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

•App in App (Proxy bzw. iFrame)

•HTML plus FBML

•Zusätzliche Parameter, Header etc.

Donnerstag, 11. Juni 2009

FBML ZOMG WTF?

Donnerstag, 11. Juni 2009

Face Book Markup Language

Donnerstag, 11. Juni 2009

<fb:fbml> <fb:header>dings</fb:header> <%- fb_tabs do -%> <%= yield :tabs %> <%- end -%> <fb:add-section-button section="profile" /> <%= yield %></fb:fbml>

Donnerstag, 11. Juni 2009

loads of tags

Donnerstag, 11. Juni 2009

Texthttp://wiki.developers.facebook.com/index.php

/FBML

Donnerstag, 11. Juni 2009

•Daten-Integration

•Cache-Hilfen

•Forms

•Styling

•Visibility

Donnerstag, 11. Juni 2009

API

Donnerstag, 11. Juni 2009

(out of scope)

Donnerstag, 11. Juni 2009

Profil-Widgets pushen

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

(Auch FBML)

Donnerstag, 11. Juni 2009

Notifications

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

Publisher

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

Facebook Connect

Donnerstag, 11. Juni 2009

(Think OAuth)

Donnerstag, 11. Juni 2009

Weitere Technologien

Donnerstag, 11. Juni 2009

FBJS

Donnerstag, 11. Juni 2009

Face Book Just Sucks

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

<%= image_tag image.small_url, :id => "gallery_image_#{image.id}", :class => "gallery-image", :onclick => "setImage(#{image.id});return false;" %>

Donnerstag, 11. Juni 2009

Aber wie?

Donnerstag, 11. Juni 2009

Facebooker

Donnerstag, 11. Juni 2009

Chad Fowler

Donnerstag, 11. Juni 2009

Mike Mangino

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

•Sehr coole API-Umsetzung

•before_filter f. Auth etc.

•Fast alle APIs abgedeckt

•Publisher (wie Mailer) f. Notifications, Profile, Profile-Publisher

•FBML-Helper

Donnerstag, 11. Juni 2009

Configure

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

Donnerstag, 11. Juni 2009

development: api_key: --------------------------------- secret_key: ---------------------------------- canvas_page_name: example callback_url: http://example:4007 pretty_errors: true set_asset_host_to_callback_url: true tunnel: public_host_username: johndoe public_host: example.com public_port: 4007 local_port: 3000 server_alive_interval: 0

test: api_key: --------------------------------- secret_key: ---------------------------------- canvas_page_name: example callback_url: http://example:4007 pretty_errors: true set_asset_host_to_callback_url: true tunnel: public_host_username: johndoe public_host: example.com public_port: 4007 local_port: 3000 server_alive_interval: 0

Donnerstag, 11. Juni 2009

rake facebooker:tunnel:start

Donnerstag, 11. Juni 2009

ssh -R :4007:localhost:3000 johndoe@example.com sleep 999999

Donnerstag, 11. Juni 2009

#/etc/ssh/sshd_config

GatewayPorts clientspecified

Donnerstag, 11. Juni 2009

$ /script/server

Donnerstag, 11. Juni 2009

example.com

facebook

client browser

dev machine

Donnerstag, 11. Juni 2009

CodePorn.random

Donnerstag, 11. Juni 2009

ApplicatioController

Donnerstag, 11. Juni 2009

# Filters added to this controller apply to all controllers in the application.# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base

include ExceptionNotifiable

helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for d...

helper_attr :current_user

attr_accessor :current_user

ensure_authenticated_to_facebook

before_filter :create_facebook_session, :set_current_user

# Scrub sensitive parameters from your log # filter_parameter_logging :password def set_current_user self.current_user = User.for(facebook_session.user.to_i, facebook_session) end end

Donnerstag, 11. Juni 2009

<fb:fbml> <style type="text/css" media="screen"> ul.image-list li h2 { margin-bottom: 5px; } .single-image { width:760px; text-align:center; margin-top:10px; } .single-image h2 { margin-bottom: 5px; } </style> <fb:header>dpa-info.com galerie</fb:header> <%- fb_tabs do -%> <%= yield :tabs %> <%- end -%> <fb:add-section-button section="profile" /> <%= yield %>

</fb:fbml>

Donnerstag, 11. Juni 2009

application.fbml.erb

Donnerstag, 11. Juni 2009

<%- content_for :tabs do -%> <%= fb_tab_item 'Gallery', root_url, :selected => true %> <%= fb_tab_item 'Invite your friends', new_invitation_url %><%- end -%>

Donnerstag, 11. Juni 2009

Profile Template

Donnerstag, 11. Juni 2009

<%- @assigns[:images].each do |image| -%> <%= link_to image_tag(image.small_url,

:title => h(image.title), :alt => h(image.title)), root_url %>

<%- end -%><%= link_to "Mehr Bilder...", gallery_url %>

Donnerstag, 11. Juni 2009

Publisher

Donnerstag, 11. Juni 2009

class GalleryPublisher < Facebooker::Rails::Publisher def image_feed_template app_link = link_to("Mehr Photos...",root_url) one_line_story_template "{*actor*} mag das Photo '{*image_title*}' #{app_link}" short_story_template "{*actor*} mag das Photo '{*image_title*}' aus der dpa-Galerie", "#{app_link}" end def image_feed(user, image) send_as :user_action from user data :image_title => image.title, :images=>[image(image.small_url,root_url)] end def profile_update(user) send_as :profile recipients user @images = DailyImage.latest.all(:limit => 10) profile render(:partial => "profile", :assigns => {:images => @images} ) profile_main render(:partial => "profile_narrow", :assigns => {:images => @images[0..3]} ) endend

Donnerstag, 11. Juni 2009

ProfilePublisher

Donnerstag, 11. Juni 2009

class ProfilePublisherController < ApplicationController skip_before_filter :ensure_authenticated_to_facebook def index

if current_user.nil? and facebook_params[:user] self.current_user = User.for(facebook_params[:user]) end if wants_interface? @images = DailyImage.latest.all(:limit => 10) render_publisher_interface(render_to_string(:partial=>"form", :assigns => {:images => @images})) else @image = DailyImage.find(params[:app_params][:id]) render_publisher_response(GalleryPublisher.create_image_feed(current_user, @image)) end endend

Donnerstag, 11. Juni 2009

some more code...

Donnerstag, 11. Juni 2009

fin

Donnerstag, 11. Juni 2009