1

我正在努力将我的应用程序与带有 spring rest 模板的 Withings api 集成。

但是,在生成 Oauth 签名时,我得到了“无效签名”。我正在尝试根据 API 规范设计一个签名,但我无法成功生成它。我已经提到了我使用的代码。请给我一些解决方案。

private String generateSignature(String baseString, String secret) throws          UnsupportedEncodingException {
    String secretKey = consumerSecret + "&";


    SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
    HMAC_SHA1SignatureMethod hmacsha = new HMAC_SHA1SignatureMethod(keySpec);
    String signatureString = hmacsha.sign(baseString);
    String base64Encode = new String((signatureString.getBytes()));
    signature = URLEncoder.encode(base64Encode, "UTF-8");

供参考, http: //oauth.withings.com/api

4

1 回答 1

1

i faced the same issues before , it seems the signature need you params ( api params + oauth params ) to be ordered alphabetically .

You need also to give a correct secret word in making you signature based uri .

you can check if you want my php oauth lib ( more particulary in AbstractService.php ) for withing here https://github.com/huitiemesens/PHPoAuthLib ( it s a fork of the original phpoauthlib with specific order for withings apis ... )

于 2015-10-08T14:51:34.537 回答