//get access token
try
{
//write the code
System.out.println("Write code :");
Scanner sc = new Scanner(System.in);
String authorizationCode=sc.nextLine();
authorizationCode=authorizationCode.replace("\\n", "");
//authorizationCode.replace(".", "");
urlToken_=urlToken_.replace(" ", "%20");
WebResource resource2=c.resource(urlToken_);
// resource2.setProperty("Content-Type", "application/x-www-form-urlencoded");
// resource2.setProperty("Content-Length", authorizationCode.length());
//resource2.accept("application/x-www-form-urlencoded");
//build path for getting access token and secret access token
//resource2.header("Content-Length", "0");
// resource2.entity(resource.header("Content-Type","application/x-www-form-urlencoded"));
// resource2.entity(resource.header("Content-Length","0"));
//construction of url with parameters
//
// OAuthParameters params = new OAuthParameters().consumerKey(clientID_);
// OAuthSecrets secrets = new OAuthSecrets().consumerSecret(clientSecret_);
//
// OAuthClientFilter filtre=new OAuthClientFilter(c.getProviders(), params, secrets);
// resource2.addFilter(filtre);
MultivaluedMap<String,String> query=new MultivaluedMapImpl();
query.add("code",authorizationCode);
query.add("client_id",clientID_);
query.add("client_secret",clientSecret_);
query.add("redirect_uri",redirectURI_);
query.add("grant_type","authorization_code");
query.add("access_type", "offline");
OAuthParameters params = new OAuthParameters().consumerKey(clientID_);
//String cr=resource2.queryParams(query).header("Content-Type", "application/x-www-form-urlencoded").post(String.class);
//String cr=resource2.queryParams(query).header("content-length", 0).post(String.class);
//String cr=resource2.queryParams(query).header("Content-Type", "application/x-www-form-urlencoded").header("Content-Length","0").post(String.class);
//String cr=resource2.queryParams(query).header("Content-Type", "application/x-www-form-urlencoded").header("Host", "
accounts.google.com").header("Content-Length",HttpHeaders.CONTENT_LENGTH).post(String.class);
//String cr=resource2.queryParams(query).header("Content-Type", "application/x-www-form-urlencoded").header("Host", "
accounts.google.com").header("Content-Length",resource2.toString().length()).post(String.class);
String cr=resource2.queryParams(query).post(String.class);
//String cr=resource2.queryParams(query);
System.out.println(cr);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}