GithubHelp home page GithubHelp logo

bukk530 / railsbook Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 580 KB

The Facebook SDK for Rails4 provides a native interface to the Graph API and Facebook Login. It is based on the Offical Facebook PHP SDK.

License: MIT License

Erlang 1.12% Ruby 75.24% JavaScript 2.62% CSS 2.82% HTML 18.20%

railsbook's Introduction

Railsbook - Facebook SDK for Rails4!

Introduction

This SDK is based on the offical Facebook PHP SDK

Usage

Configuration

To start using this gem you need to include it in your Rails4 app Gemfile:

#gem RailsBook
gem 'railsbook', github: 'bukk530/railsbook'

Save your Gemfile and run:

bundle install

Now that you have installed RailsBook you need to configure your Facebook App!

Do:

rails g rails_book:config

to generate a config/facebook_app.yml configuration file.

Open config/facebook_app.yml, it should look like this:

app_id: "YOUR APP ID"
app_secret: "YOUR SECRET"

Now go to your Facebook application and replace the App Id and Secret in your config file

If you use Git, do:

git add config/initializers/facebook.rb
git add config/facebook_app.yml

Now you should be able to play with the SDK!

Usage

Ok let's start with a simple login page:

routes.rb

Rails.application.routes.draw do
  root				   "fb_login_controller#show_login"
  get "/login",    to: "fb_login_controller#login",        as: :login
end

fb_login_controller.rb

class FbLoginController < ApplicationController
	include RailsBook
	
	# Initialize our helper (in a future version this will be a real rails helper)
	before_action do
		@facebook_login_helper = FacebookRedirectLoginHelper.new login_url, session, params
	end
	
	# In this page we will ask the user to log in via Facebook
	def show_login
		@facebook_login_url = @facebook_login_helper.get_login_url
	end
	
	# This page is called back from Facebook after the user logged in
	def login
	  facebook_session = @facebook_login_helper.get_session_from_redirect
	  @user = FacebookRequest.new(facebook_session, 'GET', '/me').execute.response
	end
end

show_login.html.erb

<a href="<%= @facebook_login_url %>">Login via Facebook!</a>

login.html.erb

<h1>Halo <%= @user['name'] %></h1>

railsbook's People

Contributors

bukk530 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.