I spent the last few days bumping my head against the wall, supporting the ability to add a contact to the Google Contacts API in my Rails 3 application. Despite many false starts, I finally made some progress by using the Ruby OAuth stone and following the instructions here: http: //everburning.com/news/google-analytics-oauth-and-ruby-oh-my/
When I follow this in the console, I get more than in my Rails application. I can create an access token, authenticate a Google service with a specific area of the contact APIs, and apply the oauth_verifier token to get the access token. But when the time comes for data entry, I get this error:
response = at.post("https://www.google.com/m8/feeds/contacts/default/full", gdata)
=>
Where does the header "readbody = true" come from and how can I get rid of it?
But this is worse in a Rails application. I have one controller action ("googlecontacts") that creates a request token and leads the user to an authentication site with Google:
def googlecontacts
@card = Card.find_by_short_link(params[:id])
@consumer = OAuth::Consumer.new(
'anonymous',
'anonymous',
{
:site => 'https://www.google.com',
:request_token_path => '/accounts/OAuthGetRequestToken',
:access_token_path => '/accounts/OAuthGetAccessToken',
:authorize_path => '/accounts/OAuthAuthorizeToken',
:signature_method => 'HMAC-SHA1',
:oauth_version => '1.0'
})
@request_token = @consumer.get_request_token(
{:oauth_callback => 'http://monkey.dev/cards/google_auth?redir='+@card.short_link},
{:scope => "https://www.google.com/m8/feeds/"}
)
session[:request_token] = @request_token
redirect_to @request_token.authorize_url
end
This seems to work; I get a work request token object and the user is sent to the Google service for authentication. The callback URL ("google_auth") must use the oauth_verifier token to create the access token. Here is the start of the controller:
def google_auth
@access_token = session[:request_token].get_access_token(:oauth_verifier=>params[:oauth_verifier])
And here where he is shit. The error in this last line is:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
But the values that are there - the session [: request_token] and params [: oauth_verifier] - are present and taken into account in this action! I can’t understand what is here.
, , , .: -)
.
.