Search code examples
javaandroidoauthflickr

Oauth Signature not getting generated


I am trying to generate an Oauth signature in order to authenticate an user in flickr.com from my android app.

According to the article in flickr.com, I have to send a signing request in order to get the signature. The hyperlink to the flickr.com guide page is:

http://www.flickr.com/services/api/auth.oauth.html#request_token

According to the post, I have to send a request like this to the flickr server in order to receive the signature key:

http://www.flickr.com/services/oauth/request_token
?oauth_nonce=89601180
&oauth_timestamp=1305583298
&oauth_consumer_key=653e7a6ecc1d528c516cc8f92cf98611
&oauth_signature_method=HMAC-SHA1
&oauth_version=1.0
&oauth_callback=http%3A%2F%2Fwww.example.com

I have send a request from my app, in the above mentioned format, but all I received is an error saying oauth_problem=parameter_absent&oauth_parameter_absent=oauth_signature.

My request code is:

HttpGet get = new HttpGet("http://www.flickr.com/services/oauth/request_token?oauth_nonce="+nonce+"&oauth_timestamp="+ts+"&oauth_consumer_key=****&oauth_signature_method=HMAC-SHA1&oauth_version=1.0");

Actually the problem is that, the url through which I am requesting for the signature is responding in a wrong way. Where it should return the signature, its asking for the signature.


Solution

  • The signing step is no request. You take the URI you have so far and transform it into the base string as seen in the documentation (URL encoding its parts and the like). The you use the HMAC-SHA1 algorithm witch takes the 2 parameters key and data. Use the base string as data and key

    is the concatenated values of the Consumer Secret and Token Secret, separated by an '&'.

    The value you get back from the algorithm (the signature) is then appended to your URI with

    &oauth_signature={ALGORITHM_OUTPUT}
    

    Using this new URI you can then request tokens.

    If you think this is too much work, check out some Java OAuth library, e.g. scribe-java.