Error 411 Google Drive for getting an access token and a refresh token after authorization

456 views
Skip to first unread message

Laurent Thulier

unread,
Feb 14, 2013, 7:39:48 AM2/14/13
to oauth...@googlegroups.com
Hey everybody, (Sorry if my english is not perfect yet)

I'm usering Jersey for REST methods in Java. I can authorize the user to accept an app, it returns me a code...
but when I want to get the access token and the refresh token with my code, an error occurs.. I don't know why, it's all the time error 411 length required
I tried many things to set the length but nothing works... I don't know if it's another problem than this.

I tried to delete the \n after pasting the code... I put a lot of things in comment to see my historic, what I tried to make it work.

Anyone Could Help me pleaaase?

This is my code:

private static String urlToken_="https://accounts.google.com/o/oauth2/token HTTP/1.1";

//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("Host", "accounts.google.com");
// 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("Host","accounts.google.com"));
// 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()); 
}
}
Reply all
Reply to author
Forward
0 new messages