invalid oauth signature error

90 views
Skip to first unread message

Ananda Krishna

unread,
Oct 11, 2012, 10:07:51 AM10/11/12
to fatsecret-p...@googlegroups.com
hi ,
I am getting this oauthSignature error:
Error Message:{ "error": {"code": 8, "message": "Invalid signature: oauth_signature 'iI0C/uiLLCGTOp WxNjd7ILv6cE='" }}
This is my code for hmac signature:
public static String computeHmac(String baseString, String key) throws Exception {
        Mac mac = Mac.getInstance("HmacSHA1");
        SecretKeySpec secret = new SecretKeySpec(key.getBytes(), mac.getAlgorithm());
        mac.init(secret);
        byte[] digest = mac.doFinal(baseString.getBytes("utf-8"));
        return (Base64.encode(digest));
       
    }

    public static String encodeUrl(String web_url) throws Exception {
        String encodedReqUrl = URLEncoder.encode(web_url, "UTF-8");
        return (encodedReqUrl);
    }

    public static String randomString() {
        final String ALPHA_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder sb = new StringBuilder(5);
        for (int i = 0; i < 5; i++) {
            int ndx = (int) (Math.random() * ALPHA_NUM.length());
            sb.append(ALPHA_NUM.charAt(ndx));
        }
        return (sb.toString());
    }

    public static String getSignaturedUrl(String methodType) throws Exception {
        String outhSignature = "";
        String finalUrl = "";
        String requestUrl = "http://platform.fatsecret.com/rest/server.api";
        String ecnodedUrl = Hmac_signature.encodeUrl(requestUrl);
        Long tstamp = System.currentTimeMillis() / 1000;
        int timestamp = tstamp.intValue();
        String nonce = Hmac_signature.randomString();
        String parameters = "oauth_consumer_key=xxxxxxx&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + timestamp + "&oauth_version=1.0&oauth_nonce="+ nonce;
        String encodedParm = Hmac_signature.encodeUrl(parameters);
        String baseString = "POST&" + ecnodedUrl + "&" + encodedParm;
        String key = "yyyyyy&";
        outhSignature = Hmac_signature.computeHmac(baseString, key);
        finalUrl = "http://platform.fatsecret.com/rest/server.api?"+parameters+"&oauth_signature="+outhSignature+"&format=json&method="+methodType;
        return (finalUrl);

    }
Please tell me where am i going wrong..
Regards,
AnandaKrishna S

Peter L

unread,
Oct 15, 2012, 1:36:34 AM10/15/12
to fatsecret-p...@googlegroups.com
Hi

Did you solve it? I have the same problem. I work on Android platform.

Thanks Peter
Reply all
Reply to author
Forward
0 new messages