I am working on a toolkit to remind fatsecret users to input their
dietary intake on android phone. So the first thing I need to do is to
implement the 3-legged OAuth authentication. However, I met the
invalid signature error when obtaining a request token.
Basically, I use the fatsecretapi to sign the baseString. What I've
modified is only to add one line to add the callback url in
generateSignature function:
parameters.put(OAUTH_CALLBACK, callbackUrl);
An example of the baseString I got is:
POST&http%3A%2F%
2Fwww.fatsecret.com%2Foauth
%2Frequest_token&oauth_callback%3Dandroidhealth%253A%252F
%252Fcom.health.addDataStore%252F%26oauth_consumer_key
%3Dd37e0bb2199a4505a397171f701e3273%26oauth_nonce
%3De697f5ae2e0a44f2a012e70a7a1cae51%26oauth_signature_method%3DHMAC-
SHA1%26oauth_timestamp%3D1301590491%26oauth_version%3D1.0
To sign it, the key I used is
String secret = consumerSecret + "&";
An example of the signature is
Gq5JzFL+0ehcxK+OrwH03Sg9sQ4=
Based on that, I post the url (url = result.getNormalizedUrl()
+"?"+result.getNormalizedRequestParameters()+ "&" + "oauth_signature"
+ "=" + URLEncoder.encode(result.getSignature(), "utf-8");), e.g.,
url:
http://www.fatsecret.com/oauth/request_token?
oauth_callback=androidhealth%3A%2F%2Fcom.health.addDataStore
%2F&oauth_consumer_key=d37e0bb2199a4505a397171f701e3273&oauth_nonce=e697f5ae2e0a44f2a012e70a7a1cae51&oauth_signature_method=HMAC-
SHA1&oauth_timestamp=1301590491&oauth_version=1.0&oauth_signature=tInl7W8oEBO1a5d7pT3EEzW6SQY
%3D
And then the error returns:
400 bad request
invalid signature: tInl7W8oEBO1a5d7pT3EEzW6SQY%3D
I try to find the bug but failed. So is anyone can help me on this?
Sincerely,
Andong