Welcome back!

Forgot your password?

Get started with Temboo and Rails

Here we'll show you how to get started with Temboo in a Rails app. We'll use Facebook OAuth, which lets any Facebook user log in to Facebook and grant your app access to their account, as an example to illustrate everything you need to know about how to use Temboo with Rails. Our simple app logs users in and displays some info about their Facebook profile.

In order to follow this example, you'll need Ruby 1.9 (or later) and a Rails web application server listening on http://0.0.0.0:3000.

If you don't already have Rails installed, you can use the following command:

sudo gem install rails

Run our Facebook OAuth Example

1 Log in to Temboo. If you don't already have an account, you can register for free here.

2 If you haven't already, download and install the Ruby SDK gem as described in our getting started tutorial.

3 Create a new Facebook app via the Facebook developer console using the Apps menu at the top of the page. Once you've created a new App, click the Settings tab on the left, select + Add Platform, and choose the Website option. Set up your Temboo callback URL by specifying the following URL as your Site URL:

https://ACCOUNT_NAME.temboolive.com/callback/

4 Choose a location for your project and run the following command in your terminal:

6 Add gem 'temboo' and the SDK version number to your Gemfile. You'll need to replace x.x.x below with something like 2.6.0 i.e., the version number of the Temboo Gem that you downloaded from our website:

gem 'temboo', '<= x.x.x'

7 Run the bundle install command:

bundle install

8 Populate the views:

/oauth_demo/app/views/facebook_oauth/index.html.erb

<h1>
This is a simple app that demonstrates using the Temboo SDK to perform Facebook
OAuth authentication.
</h1>
<p><a href="/facebook_oauth/initialize_oauth">Login with Facebook</a>

12 Once you've been redirected to Facebook, you can log in and grant the application access to your Facebook account. At this point in the example, you should be redirected back to your application where you'll see the user profile information in JSON format. That's it! The process is example the same for using any of the other 2000+ Choreos in our Library.

Taking a closer look at the code

This example includes two main functions for completing the OAuth process:

initialize_oauth: This executes when the user clicks the Login with Facebook link.

finalize_oauth: This executes when the user is redirected to /finalize_oauth after granting the application access.

In the initialize method, we get the Authorization URL and Callback ID:

When beginning the OAuth process, the InitializeOAuth Choreo will always return a CallbackID used to retrieve OAuth callback data after the user redirects back to your app's page.

Your application can use the Callback ID to finish the OAuth process and retrieve the user's access token.

Below is the function that generates the Callback ID and redirects the user to the Authorization URL:

What's Next?

We're all finished! This Rails application executes the OAuth flow, and retrieves information about your app's user. We have OAuth support for many of the other APIs in our Library.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Commit Code to GitHub

Commit Temboo-generated code directly to GitHub and share with the world. Learn more.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.