我正在努力将我的应用程序与带有spring rest模板的Withings集成在一起。
但是,在生成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
发布于 2015-10-08 22:51:35
我之前遇到过同样的问题,似乎签名需要你的参数( api参数+ oauth参数)按字母顺序排序。
您还需要提供一个正确的秘密字,使您的签名基于uri。
您可以查看是否需要我的php oauth库(在AbstractService.php中有更详细的说明),在这里使用https://github.com/huitiemesens/PHPoAuthLib (它是原始phpoauthlib的分支,带有withing api的特定顺序……)。
https://stackoverflow.com/questions/27777644
复制相似问题