2

我正在将我的应用程序与 Hubspot CRM 集成。我需要使用 OAuth2.0 获取访问令牌。我启动了授权并尝试使用 HTTPClient 获取访问令牌。但我无法得到回应。我在下面添加了我的代码。我在做什么错误,当我用来启动授权时,我使用相同的重定向 uri。

代码

String grant_type = "authorization_code";

            HttpPost post = new HttpPost("https://api.hubapi.com/oauth/v1/token");
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("code", code));
            nvps.add(new BasicNameValuePair("client_id", client_id));
            nvps.add(new BasicNameValuePair("client_secret", client_secret));
            nvps.add(new BasicNameValuePair("redirect_uri", redirect_uri));
            nvps.add(new BasicNameValuePair("grant_type", grant_type));
            post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            DefaultHttpClient httpClients = new DefaultHttpClient();
            HttpResponse response = httpClients.execute(post);

响应错误

HTTP/1.1 400 Bad Request
{"status":"BAD_AUTH_CODE","message":"missing or unknown auth code","correlationId":"e33b84e6-6a60-47c4-8f66-d2826fcada44","requestId":"e74fa273f7e927a21dd5a0676c0f0e61"}
4

0 回答 0