我想要播放7个数字剪辑的预览,这些剪辑是从Echonest获得的。为此,我希望以编程方式为每个请求生成oauth签名。
播放clip- http://previews.7digital.com/clip/1234的网址,但它需要两条腿的oAuth。
为此,我使用了下面的代码,这些代码是我从stackoverflow获得的。
private static final String HMAC_SHA1 = "HmacSHA1";
private static final String ENC = "UTF-8";
private String getSignature(String url, String params)
throws UnsupportedEncodingException, NoSuchAlgorithmException,
InvalidKeyException {
StringBuilder base = new StringBuilder();
base.append("GET&");
base.append(url);
base.append("&");
base.append(params);
System.out.println("String for oauth_signature generation:" + base);
byte[] keyBytes = (DIGITAL_CONSUMER_SECRET + "&").getBytes();
SecretKey key = new SecretKeySpec(keyBytes, HMAC_SHA1);
Mac mac = Mac.getInstance(HMAC_SHA1);
mac.init(key);
return new String(base64.encode(mac.doFinal(base.toString().getBytes(
ENC))), ENC).trim();
}但是当我点击播放剪辑的最终url时,我得到了无效的签名错误。
我可以播放剪辑时,我使用7digital工具生成的网址。http://7digital.github.io/oauth-reference-page/
但我需要为每个播放请求以编程方式生成最终的url。关于这一点,请帮助我。
发布于 2014-08-07 18:53:59
7数字android sdk可以在这里找到,其中包含生成Oauth签名https://github.com/7digital/7digital-Android-SDK的示例文档
发布于 2014-08-13 20:52:58
您正在对整个基本字符串进行编码,而应分别对基本字符串的三个部分进行编码,不得对“&”字符进行编码。
使用my OAuth reference页面将生成的内容与参考实现进行比较:https://bettiolo.github.io/oauth-reference-page/
该规范包含有关基本字符串生成的更多信息:http://oauth.net/core/1.0a/#anchor13
https://stackoverflow.com/questions/25174681
复制相似问题