Java 如何为谷歌云API生成访问令牌?

Java 如何为谷歌云API生成访问令牌?,java,oauth-2.0,google-api,access-token,google-oauth,Java,Oauth 2.0,Google Api,Access Token,Google Oauth,我试着用下面的方法 public class GoogleOAuth2 { String authURL = "https://accounts.google.com/o/oauth2/auth"; String tokenURL = "https://oauth2.googleapis.com/token"; public void execute() { try { HttpClient httpclient = new DefaultHttpClient();

我试着用下面的方法

public class GoogleOAuth2 {
String authURL = "https://accounts.google.com/o/oauth2/auth";
String tokenURL = "https://oauth2.googleapis.com/token";

public void execute() {
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost post = new HttpPost(tokenURL);
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("client_id",
                "*********"));
        params.add(new BasicNameValuePair("client_secret", "*****"));
        params.add(new BasicNameValuePair("grant_type", "Authorization Code"));
        params.add(new BasicNameValuePair("redirect_url", "https://localhost:8080"));
        params.add(new BasicNameValuePair("scope", "https://www.googleapis.com/auth/cloud-platform"));
        post.setEntity(new UrlEncodedFormEntity(params));
        HttpResponse response = httpclient.execute(post);
        String body = EntityUtils.toString(response.getEntity());
        System.out.println(body);
    } catch (Exception ex) {
        System.out.println("Catched an error in Authenticating user : " + ex.getMessage());
    }
}}
我错过了什么? 你能告诉我正确的方向吗?我尝试过使用邮递员,我能够从这里获得访问令牌

{
  "error": "unsupported_grant_type",
  "error_description": "Invalid grant_type: Authorization Code"
}