Using the API with Ruby

We'll assume you've had a read through the  guide here about setting up your application on CT.

Learn to access the API with Ruby
Ok, so now we've done it with Curl, we'll show you how to do with Ruby and the Oauth2 gem. Make sure you've installed oauth2:
gem install oauth2
Open up a Rails or irb console.
First, Create a Client
client =, app_secret, :site => '')
That should give you something like this:
#<OAuth2::Client:0x007fc76195cad8 @id="f52d8b42e20c1d2808468f5a90f3a838316876aaf1db9efa320d42a65e853a49", @secret="e67534a389c215959e6e72451dfc53e9e922b2e58ae18d26e3403c26610b36f7", @site="", @options={:authorize_url=>"/oauth/authorize", :token_url=>"/oauth/token", :token_method=>:post, :connection_opts=>{}, :connection_build=>nil, :max_redirects=>5, :raise_errors=>true}>
Get the URL
client.auth_code.authorize_url(redirect_uri: callback)
Where callback is your callback URL - it must match.
The output will look like this:
=> ""
Paste this into your browser. Login as before and confirm the authorisation.
Exchanging the Code for a Token
You should be redirected back to your site. Grab the code from the URL.
token = client.auth_code.get_token(code, :redirect_uri => callback)
That should return an object. To get the access token, just use:
=> 66d3af95e474eb7eba7111e9644247dab60f2fe8f18d53bc968caaf1110e9595
And there you go!
Common Problems
The redirect uri included is not valid.
If you're using curl to test, please make sure your redirect URL is properly encoded. For example, the request should look like this:
You should also ensure your redirect url matches the callback url you've set in your application settings. Make sure there's no trailing slashes etc.
Read the API docs
Don't forget, the API docs are here: