我正在努力将我的应用程序与带有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
我之前遇到过同样的问题,似乎签名需要你参数(API参数+OAuth参数)按字母顺序排序。
您还需要给出一个正确的秘密词来使您基于签名的uri。
你可以检查你是否想要我的php oauth lib(在AbstractService中更具体.php)在这里https://github.com/huitiemesens/PHPoAuthLib(它是原始 Phpoauthlib 的一个分支,具有 withings API 的特定顺序......