Oauth 2.0 Oauth不工作的CX api
我正在尝试使用oauth for CX公开api,我遵循了他们的文档,仍然收到HTTP错误请求错误,下面是代码-Oauth 2.0 Oauth不工作的CX api,oauth-2.0,Oauth 2.0,我正在尝试使用oauth for CX公开api,我遵循了他们的文档,仍然收到HTTP错误请求错误,下面是代码- String method = "POST"; String code = ""; NameValuePair[] data = { new NameValuePair("grant_type", "authorization_code"), n
String method = "POST";
String code = "";
NameValuePair[] data = {
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", code),
new NameValuePair("redirect_uri",URLEncoder.encode(CALLBACK_URL, "UTF-8"))
};
String secret = CONSUMER_KEY+":"+CONSUMER_SECRET;
String encodedSecret = Base64.encodeBase64String(secret.getBytes("UTF-8"));
org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
PostMethod httpMethod = new PostMethod(ACCESS_TOKEN_ENDPOINT_URL);
httpMethod.addRequestHeader("Authorization","Basic "+encodedSecret);
httpMethod.setRequestBody(data);
System.out.println("HTTP call -- " + method + " " + ACCESS_TOKEN_ENDPOINT_URL);
httpClient.executeMethod(httpMethod);
谢谢,
Hemant我已经测试了以下对代码的轻微修改,它可以正常工作。你可以再检查一下 您的密钥已被批准鉴于 您看到的错误。 您正在使用正确的访问\u令牌\u端点\u URL 尝试使身份验证代码响应和令牌请求的重定向uri相同
String method = "POST";
String authCode = "[AUTH-CODE-HERE]";
String CONSUMER_KEY="[YOUR-KEY-HERE]";
String CONSUMER_SECRET="[YOUR-SECRET-HERE]";
String ACCESS_TOKEN_ENDPOINT_URL="https://api.cx.com/1/oauth/token";
String REDIRECT_URI="[YOUR-REDIRECT-HERE]";
NameValuePair[] data = {
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", authCode),
new NameValuePair("redirect_uri", REDIRECT_URI)
};
String secret = CONSUMER_KEY+":"+CONSUMER_SECRET;
String encodedSecret = Base64.encodeBase64String(secret.getBytes("UTF-8"));
PostMethod httpMethod = new PostMethod(ACCESS_TOKEN_ENDPOINT_URL);
httpMethod.addRequestHeader("Authorization","Basic "+encodedSecret);
httpMethod.setRequestBody(data);
System.out.println("HTTP call -- " + method + " " + ACCESS_TOKEN_ENDPOINT_URL);
int responseCode = httpClient.executeMethod(httpMethod);
System.out.println(responseCode);
System.out.println(httpMethod.getResponseBodyAsString());
如果您仍然遇到问题,是否可以发布以下行的结果:System.out.printlnhttmpmethod.getResponseBodyAsString CX开发者API已停止使用。
很抱歉给您带来不便。请提供API文档的链接,因为不完全清楚您所指的是哪一个提供程序CX。这里是-您是否在其他OAuth提供程序中尝试了相同的代码,只是为了验证问题是否出在CX上?