I'm trying to use Faraday with Rails 4 for Google API Oauth in below code:
class GoogleApisController < ApplicationController
def oauth2callback
require 'faraday'
render layout: false
conn = Faraday.new(:url => 'https://accounts.google.com',:ssl => {:verify => false}) do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
@result = conn.post '/o/oauth2/token', {'code' => params[:code],
'client_id' => "some_id",
'client_secret' => "some_secret",
'redirect_uri' => "some_redirect_uri",
'grant_type' => 'authorization_code'}
end
end
But when I do @result.body.inspect it doesn't return anything.
So @result return nil and doesn't seem to process at all.
However when I try the above codes in liveshell it seems to work.
Is there a reason why this is happening?
If you try to
renderbefore you instantiate the object you are trying torender, the template won't actually have anything in it. Moving therenderstatement to the bottom of the method will take care of the issue.