Mail Java Sample Code not working

Ravi26 Aug 2010 5:20 PM
Hello,

We are writing a piece of Java code to interact with the yahoo! mail API. We are following the steps exactly as stated here:
http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html

But it works upto Step 4. After getting the token, when we make a call to the API, it gives back an error saying "The token is invalid"...

Here are the details:

These are the steps in detail. The step in question seems to be Step 5 (marked in red):
Step 1 - Sign Up and Get a Consumer Key

After signing up we received:

CONSUMER_KEY = dj0yJmk9Uk5TVVBRZUdxN2VLJmQ9WVdrOVkyZGpZWEJPTm04bWNHbzlOVGsxT0RVeE16azAmc=1jb25z
dW1lcnNlY3JldCZ4PTdk

CONSUMER_SECRET = e9b7fadccda0ff23e0d7c76accbd509a7688f955



Step 2 - Get a Request Token (get_request_token)

After getting the consumer key and secret, we requested for a request token using the following URL:

https://api.login.yahoo.com/oauth/v2/get_re...token<=a>?
oauth_nonce=aaa
&oauth_timestamp=1268919814
&oauth_consumer_key=<CONSUMER_KEY>
&oauth_signature_method=plaintext
&oauth_signature=<CONSUMER_SECRET>
&oauth_version=1.0
&oauth_callback=oob

And in response we got the following parameter values

oauth_token=ebarq7d
&oauth_token_secret=5f92bc99fc7d389be3a1044d3553f1=2e7c1bbea
&oauth_expires_in=3600
&xoauth_request_auth_url=https%3A%2F%2Fapi.login.yahoo.com%2Foauth%2Fv2%2Frequest_auth%3=oauth_token%3Debarq7d
&oauth_callback_confirmed=true

Step 3 - Get User Authorization (request_auth)

After getting the Request Token from Yahoo, we used the browser and browsed to the following URL:

https://api.login.yahoo.com/oauth/v2/reques..._FROM_STEP2>


This URL contains the request token we got from Step 2 as parameter value for oauth_token. It presents the user with a login screen, where we enter credentials of our yahoo account.


In response we get a Verifier code, which we need to pass to the next step.


Step 4 - Exchange the Request Token and OAuth Verifier for an Access Token
(get_token)

After we received the Verifier code in Step 3 we pass it to the following URL

https://api.login.yahoo.com/oauth/v2/get_token?
auth_consumer_key=<CONSUMER_KEY>
&oauth_signature_method=PLAINTEXT
&oauth_version=1.0
&oauth_verifier=<VERIFIER_FROM_STEP3>
&oauth_token=<REQUEST_TOKEN_FROM_STEP2>
&oauth_timestamp=1268920729
&oauth_nonce=8B9SpF
&oauth_signature=<CONSUMER_SECRET>+<AUTH_TOKEN_SECRET_FROM_STEP2>

We get a response from Yahoo! that looks like this:

oauth_token=<some long token value>
&oauth_token_secret=c5a9684d3a3aa22aa051308987219e=b8d6982fc
&oauth_expires_in=3600
&oauth_session_handle=AKVdNElJthnrHDwnYDuj6fJ2ayRb=vkePz9AKwi9dQAfb4bd
&oauth_authorization_expires_in=919314350
&xoauth_yahoo_guid=DKXSX6Q5TA5SVNARZLUJU5AW7A

Step 5:


We can then use this access token towards requests to Yahoo! Web services. For this we downloaded the sample java code from Yahoo! Mail Web Service Code Samples (http://developer.yahoo.com/mail/code/mail_java.zip)


In this sample code we need to provide the Application ID, Shared Secret and user token. We think it is after this step that we might be doing something wrong.



The Application Id we provide is one that we got at time of registration. So
application ID for our application is
(2CHO.pnIkY3R6364sR61aQj8xZUusUTNTdqezNjt8mqP4w--) and shared secret is
(4434ce37c2fbd9c7f53effe8de369732)

One question is: Are this Application ID and Shared secret different from Consumer Key and
Consumer secret?


Also, the token we provide is the token we received in step 4. Once we run this sample code with the credentials using following URL:

https://api.login.yahoo.com/WSLogin/V1/wspw...b0b75f0948c9646


we get the following error:

"The token is invalid..."


Note that the PHP sample code that was provided to us works fine with our consumer key
and consumer secret. And that application does not even ask for application id or
shared secret.

We even tried comparing PHP code with Java sample code on the yahoo developer site and what we found is that both are doing different kinds of processing for fetching signature in step 4. PHP sample is using a consumer key, consumer secret, token, token secret and java code is using application Id, shared secret and token only.

Thanks
Ravi
Elisabeth6 Feb 2012 11:58 AM
I can open the homepage , but can&#39;t read my emails all coded javascript???<br><br>Appreciate your reply.
Ram16 Feb 2012 3:34 PM
refer https://github.com/ramiyer/YahooMailApiSample for sample java code.
Sandeep24 Feb 2012 4:07 AM
After refresh old token how can login using new token with out authorization code using java code.