Hi,
I am trying to use REST APIs for fatsecret in Android application.
I am getting "Invalid signature : oauth signature" error. I am trying to call food.get function through REST api.
My function which calculates the signature is:
private String ComputeSha(String s, String keyVal) throws
UnsupportedEncodingException, NoSuchAlgorithmException,
InvalidKeyException {
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec key = new SecretKeySpec((keyVal).getBytes(),
"HmacSHA1");
mac.init(key);
byte[] bytes = mac.doFinal(s.getBytes());
return new String(Base64.encode(bytes,0));
}
My base string is (when POST method used) :
POST&http%3A%2F%
2Fplatform.fatsecret.com%2Frest%2Fserver.api&food_id%3D33691%26method%3Dfood.get%26oauth_consumer_key%xxxxxx%26oauth_nonce%3D1358986070%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1347873420%26oauth_version%3D1.0
key used : "consumer key&"
I am consistently getting invalid signature error.
Output received is:
<?xml version="1.0" encoding="utf-8" ?>
<code>8</code>
<message>Invalid signature: oauth_signature 'O53sUmirpasamNVVIsuwsbyuyEI=
09-17 15:05:00.885: E/response--->(12420): '</message>
</error>
Can anybody help?
Thanks,
Charuhas Vidwans.