tags:

views:

259

answers:

1

I'm trying to connect to yahoo via oauth. I'm using the oauth gem with ruby.

I can successfully get an access token, but then I'm no able to use it to make any call. Here's my code:

def oauth        
  OAuth::Consumer.new(ApplicationConfig['yahoo']['access_token'],
      ApplicationConfig['yahoo']['secret'],
      {
        :site                 => 'https://api.login.yahoo.com', 
        :scheme               => :query_string, 
        :http_method          => :get, 
        :request_token_path   => '/oauth/v2/get_request_token', 
        :access_token_path    => '/oauth/v2/get_token', 
        :authorize_path       => '/oauth/v2/request_auth',
        :oauth_callback => 'http://my_callback'
  })
end

def oauth_api
  OAuth::Consumer.new(ApplicationConfig['yahoo']['access_token'],
      ApplicationConfig['yahoo']['secret'],
      {
        :site                 => 'http://address.yahooapis.com', 
        :scheme               => :header, 
        :realm                => 'yahooapis.com', 
        :http_method          => :get,
        :request_token_path   => '/oauth/v2/get_request_token', 
        :access_token_path    => '/oauth/v2/get_token', 
        :authorize_path       => '/oauth/v2/request_auth'
  })
end

@request_token = oauth.get_request_token( { :oauth_callback => 'my_callback' } )

# go to @request_token.authorize_url

@access_token = @request_token.get_access_token({ :oauth_verifier => params[:oauth_verifier] })

@access_token.consumer = oauth_api

## Now I have an access token, but if I do something like:

response = @access_token.get('/v1/searchContacts')

## Then I get

#<Net::HTTPForbidden 403 Forbidden readbody=true>
# >> response.body
# => "<!-- web231.address.pim.re3.yahoo.com uncompressed/chunked Wed Jan 13 01:15:46 PST 2010 -->\n"

Basically I would expect that to work.

I've not been able to find any working example on how to connect to yahoo with Ruby. I hope someone else has done this before and he/she's willing to help.

A: 

Are you working on a Web o Non-Web project?... that's important to know

Roman Gonzalez