Using Ruby OAuth for Contacts API

Hi all,
I've been trying to work with the Yahoo Contacts API using the latest
version of Ruby OAuth, but I'm not sure if I'm getting hung up with
the last stage of the authorization process, or something in the API.
I hope you can help me figure that out.

Using the current version of OAuth, I'm able to apparently receive a
working access key. I have a controller which requests the
request_token like so:

@consumer = OAuth::Consumer.new(api_key, shared_secret,
:site => 'https://api.login.yahoo.com',
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
:authorize_path => '/oauth/v2/request_auth'
:signature_method => 'HMAC-SHA1',
:oauth_version => '1.0'

@request_token = @consumer.get_request_token(
{:oauth_callback => 'http://contactmonkey.com/cards/yahoo_auth?

I get an apparently good request token from this, and proceed after
authorization in the new controller method:

@access_token =

I get an apparently good access token from this as well. It's only
when I start using the API that things get pear-shaped.

# make initial contact so we get a contact ID
yahoo_guid = @access_token.params[:xoauth_yahoo_guid]
@response = @access_token.request(:post, 'http://social.yahooapis.com/
v1/user/' + yahoo_guid + '/contacts')

When I inspect the response body, I get this:

<?xml version=\"1.0\" encoding=\"utf-8\"?><error xmlns=\"http://social.yahooapis.com/v1/schema.rng\" xmlns:yahoo=\"http://www.yahooapis.com/v1/base.rng\" yahoo:uri=\"http://www.yahooapis.com/v1/errors/415\" yahoo:lang=\"en-US\"><description>Requested representation not available for the resource</description><detail>Invalid media type</detail></error>

I've seen in many places that there's some incompatibility between the
Yahoo OAuth implementation and the Ruby OAuth gem. But I'm not sure if
that information is out of date (I'm using the current 0.4.4).

Thanks for any help you can offer!

1 Reply
  • Although this article is a little old, I wanted to just wanted to say thanks for the great starting point. I quickly realized that you were 99% of the way to success minus you used a ":post" instead of a ":get". If you were creating a new contact then you'd use a post, but since you were retrieving data you needed to use a get.

    QUOTE( VEGH @ 13 Jan 2011 9:09 AM)
    @response = @access_token.request(:post, 'http://social.yahooapis.com/
    v1/user/' + yahoo_guid + '/contacts')

    In addition, I leveraged oauth-plugin, which stores the access tokens for later use. Yahoo is one of those "special" cases where the access token expires after so much time (search around and people will tell you this until your ears bleed). The articles in Google kept leading me to believe that using oauth was not possible with Yahoo's API, but that is not actually true. I just had to add some handling around that concept and experiment with the configuration settings.

    Configuration for oauth-plugin:
        :key=>"<YOUR KEY>",
        :secret=>"<YOUR SECRET>",
        :expose => false,
        :oauth_version => 1,
          :site => 'https://api.login.yahoo.com',
          :request_token_path => "/oauth/v2/get_request_token",
          :access_token_path => "/oauth/v2/get_token",
          :authorize_path => "/oauth/v2/request_auth",
          :signature_method => 'HMAC-SHA1',
          :oauth_version => '1.0'
    Hope this information helps others out there,

Recent Posts

in OAuth General Discussion YDN SDKs