2014-10-09 173 views
1

我已經使用谷歌OAuth與Java身份驗證。當我登錄時,我會重定向到一個頁面,我得到這樣的URI這樣的http://www.demo.com/demo/PROJECTNAME/oauthRedirect?state=google;294822862&code=4/aUEAqsMu7o074wsJymyAK9CMseWR.YlkPPRXJzt8Vcp7tdiljKKbHfgXpkQI 但當我嘗試刷新頁面它給了我錯誤之後從谷歌OAuth刷新後無法刷新頁面

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request 
{ 
    "error" : "invalid_grant", 
    "error_description" : "Invalid code." 
} 
com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:103) 
com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303) 
com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.execute(GoogleAuthorizationCodeTokenRequest.java:175) 
com.mob.googleoauth.GoogleAuthHelper.getUserInfoJson(GoogleAuthHelper.java:108) 
com.mob.controller.UserController.user(UserController.java:55) 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
java.lang.reflect.Method.invoke(Method.java:606) 
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) 
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) 
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) 
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) 
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:620) 
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
+0

檢查您的服務器:invalid_grant通常意味着您的服務器時鐘與NTP不同步。 – DaImTo 2014-10-09 11:12:21

+0

感謝您的回覆我嘗試過,但仍然無法正常工作! – UtkarshBhavsar 2014-10-09 11:21:47

回答

0

在谷歌上的成功認證,它會送你(你的情況4/aUEAqsMu7o074wsJymyAK9CMseWR.YlkPPRXJzt8Vcp7tdiljKKbHfgXpkQI)代碼。再次使用此代碼,您可以通過POST請求訪問Google API。那麼谷歌會給你發送access_token。有了這個access_token,再次調用Google API,它將返回所需的數據。