Using Ruby OAuth to Connect to Yahoo Contacts API

I'm trying to work with the Yahoo Contacts API using the latest version of Ruby OAuth, but I'm not sure if I was hung in the last step of the authorization process or something in the API. I hope you can help me figure it out.

Using the current version of OAuth, I can apparently get a working passkey. I have a controller that requests request_token like this:

@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?redir...@card.short_link} 
) 

I get a clearly good request token from this and continue after authorization in the new controller method:

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

I get a clearly good access token from this. This is only when I start using the API, things become 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 check the body of the response, I get the following:

<?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>

, Yahoo OAuth Ruby OAuth. , ( 0.4.4).

, ! .

:. :

@response =  @access_token.request(:post, 'http://social.yahooapis.com/v1/user/' + yahoo_guid + '/contacts', entry, { 'Content-Type' => 'application/xml' } )

"content-type". "text/xml", . . . !

+3
2

HTTP 415, , . API Yahoo API . :

1.) "Accept" HTTP Header ( XML, JSON).

2.) = xml ? format = json.

+1
0

Source: https://habr.com/ru/post/1785341/


All Articles