}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
Token token = _consumer.getToken(_googleEndpoint.getConsumerKey(), request);
switch(token.getState())
{
case Token.UNITIALIZED:
UrlEncodedParameterMap params = new UrlEncodedParameterMap()
.add("scope", "http://www.google.com/m8/feeds/")
.add(Constants.OAUTH_CALLBACK, request.getRequestURL().toString());
Response r = _consumer.fetchToken(_googleEndpoint, params, TokenExchange.REQUEST_TOKEN,
token);
if(r.getStatus()==200 && token.getState()==Token.UNAUTHORIZED)
{
// unauthorized request token
_consumer.saveToken(token, request, response);
StringBuilder urlBuffer = Transport.buildAuthUrl(
_googleEndpoint.getAuthorizationUrl(), token);
Transport.appendToUrl("hd", "default", urlBuffer);
response.sendRedirect(urlBuffer.toString());
}
break;
case Token.UNAUTHORIZED:
if(token.authorize(request.getParameter(Constants.OAUTH_TOKEN),
request.getParameter(Constants.OAUTH_VERIFIER)))
{
if(fetchAccessToken(token, request, response))
queryGoogleContacts(token, request, response);
else