I try to authorize to yahoo api by example on http://developer.yahoo.com/mail/code/ for JAX-WS. I get an exception:
Exception in thread "main" ua.com.stormlabs.gap.yahoomail.BrowserBasedAuthManager$AuthException: Signature mismatch
at ua.com.stormlabs.gap.yahoomail.BrowserBasedAuthManager.authenticate(BrowserBasedAuthManager.java:59)
at ua.com.stormlabs.gap.yahoomail.JaxWsSample.main(JaxWsSample.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.Delega开发者_开发问答tingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
My code fragment:
String token = "<very_big_token>";
BrowserBasedAuthManager authManager = new BrowserBasedAuthManager(appid, secret);
authManager.setToken(token);
authManager.authenticate();
And authenticate() method:
try {
long time = System.currentTimeMillis() / 1000;
String signatureUrl = "/WSLogin/V1/wspwtoken_login?appid=" +
URLEncoder.encode(this.appid, "UTF-8") + "&token=" + URLEncoder.encode(this.token, "UTF-8") +
"&ts=" + time;
MessageDigest digest = MessageDigest.getInstance("MD5");
String signature = new BigInteger(1, digest.digest((signatureUrl + this.secret).getBytes())).toString(16);
String requestUrl = "https://api.login.yahoo.com" + signatureUrl + "&sig=" + URLEncoder.encode(signature, "UTF-8");
Document response = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new URL(requestUrl).openStream());
if (response.getElementsByTagName("Error").getLength() == 0) {
this.cookie = response.getElementsByTagName("Cookie").item(0).getTextContent();
this.wssid = response.getElementsByTagName("WSSID").item(0).getTextContent();
} else {
throw new AuthException(response.getElementsByTagName("ErrorDescription").item(0).getTextContent());
}
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new AuthException("Error parsing XML", e);
} catch (IOException e) {
throw new AuthException("Communication failure", e);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
}
Where is a problem? I also found this forum thread: http://developer.yahoo.com/forum/Yahoo-Mail-Web-Services-API/-Authorization-failed-error-when-using-Yahoo/1304709008000-9792a6b7-5492-3863-a865-ab36576e399f but it doesn't help me.
精彩评论