豆瓣开放平台, oauth 认证获取getAccessToken() 失败
这是授权时的url
http://www.douban.com/service/auth/authorize?
oauth_token=957cafde5a115a79c0760f9b0e340f6b&oauth_callback=http://localhost:8080/ART/user/doubanOAuth.action
这是授权后的跳转的url
http://localhost:8080/ART/user/doubanOAuth.php?oauth_token=957cafde5a115a79c0760f9b0e340f6b
通过用户授权后,通过response重定向到 doubanLogin.action
response.sendRedirect(myService.getAuthorizationUrl("http://localhost:8080/ART/user/doubanLogin.action"));
下面是doubanLogin.action 里面的代码
String requestToken = request.getParameter("oauth_token"); DoubanService myService = new DoubanService("subApplication", apiKey, secret); if(requestToken != null) { myService=(DoubanService) request.getSession().getAttribute("DoubanService");// // step2 : user give the authorization and prepare to get the request token Cookie[] cookies = request.getCookies(); if (cookies == null) { System.err.println("request token secret not found in cookie"); return; } Cookie c = cookies[0];// // set request token and token secret myService.setRequestTokenSecret(c.getValue()); myService.setRequestToken(requestToken);// // get request token [color=#FF0000]myService.getAccessToken();[/color]net.oauth.OAuthProblemException at net.oauth.client.OAuthHttpClient.invoke(OAuthHttpClient.java:71) at net.oauth.client.OAuthClient.invoke(OAuthClient.java:96) at net.oauth.client.OAuthClient.invoke(OAuthClient.java:102) at com.google.gdata.client.douban.DoubanService.getAccessToken(Unknown Source) at com.art.action.UserAction.doubanLogin(UserAction.java:500) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597)com.google.gdata.util.AuthenticationException: Unauthorizedno authat com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:570) at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:559) at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:542) at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:521) at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:531) at com.google.gdata.client.Service.getEntry(Service.java:982) at com.google.gdata.client.Service.getEntry(Service.java:908) at com.google.gdata.client.douban.DoubanService.getEntry(Unknown Source) at com.google.gdata.client.douban.DoubanService.getAuthorizedUser(Unknown Source) at com.art.action.UserAction.doubanLogin(UserAction.java:505) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)