I got things working with the following code. I made a mistake by marking the data in query string as well as setting content-type and content-length explicitly. Content-type is the by default "application/x-www-form-urlencode". Got the solution by random click.
var urlToken ="https://accounts.google.com/o/oauth2/token"+
var dataValue = "client_id=<<my client id>>&" +
"client_secret=<<my client secret>>&" +
"code=<<Device code received in first step>>&" +
"grant_type=http://oauth.net/grant_type/device/1.0";
$.ajax({
url:urlToken,
data:dataValue,
crossDomain:true,
type:"POST",
success:function(response){
if(response.error != null){
<<Call the same function again>>;
}
else{
console.log("Access Token :" + response.access_token);
console.log("Token Type : " + response.token_type);
console.log("Expires : " + response.expires_in);
console.log("Refresh Token : " + response.refresh_token);
}
},
error:failure
});
Thanks WTK