Description
https://api.zoom.us/v2/users/{userid}/token always return 401.
Error
it returns ,
124
Invalid access token.
Which App Type (OAuth / Chatbot / JWT / Webhook)?
api
Which Endpoint/s?
https://api.zoom.us/v2/users/{userid}/tokenhttps://api.zoom.us/v2/users/{userid}/token
When i create a jwt with credentials from developer console and try to send a get request it always returns 401 error. But with same credentials i am able to build simple app which creates and joins room.
this is my code :
private String getZoomToken() {
try {
URL zoomTokenEndpoint = new URL("https://api.zoom.us/v2/users/" + "bhdrgl06@gmail.com" + "/token?type=token&access_token=" + getJWT());
HttpsURLConnection connection = (HttpsURLConnection) zoomTokenEndpoint.openConnection();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream responseBody = connection.getInputStream();
InputStreamReader responseBodyReader = new InputStreamReader(responseBody, "UTF-8");
BufferedReader streamReader = new BufferedReader(responseBodyReader);
StringBuilder responseStrBuilder = new StringBuilder();
//get JSON String
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
connection.disconnect();
JSONObject jsonObject = new JSONObject(responseStrBuilder.toString());
return jsonObject.getString("token");
} else {
Log.d("dasdas", "error in connection");
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return "";
}
private String getJWT() {
long time = System.currentTimeMillis()/1000 + 3600;
String header = "{\"alg\": \"HS256\", \"typ\": \"JWT\"}";
String payload = "{\"iss\": \"" + AppConstant.Zoom_Key + "\"" + ", \"exp\": " + String.valueOf(time) + "}";
try {
String headerBase64Str = Base64.encodeToString(header.getBytes("utf-8"), Base64.NO_WRAP| Base64.NO_PADDING | Base64.URL_SAFE);
String payloadBase64Str = Base64.encodeToString(payload.getBytes("utf-8"), Base64.NO_WRAP| Base64.NO_PADDING | Base64.URL_SAFE);
final Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(AppConstant.Zoom_Secret.getBytes(), "HmacSHA256");
mac.init(secretKeySpec);
byte[] digest = mac.doFinal((headerBase64Str + "." + payloadBase64Str).getBytes());
return headerBase64Str + "." + payloadBase64Str + "." + Base64.encodeToString(digest, Base64.NO_WRAP| Base64.NO_PADDING | Base64.URL_SAFE);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
return "";
}