I am running the following piece of code for a test. I get back a valid token. I tested it at JWT…
The response returns a response.IsSuccessful as false and no content. I expected a list of users…
I put my API key and Secret Key in where it is commented.
Thanks for any help
var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
var now = DateTime.UtcNow;
var apiSecret = "<your API secret here>";
byte[] symmetricKey = Encoding.ASCII.GetBytes(apiSecret);
var tokenDescriptor = new SecurityTokenDescriptor
{
Issuer = "<your API key here>",
Expires = now.AddSeconds(30),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);
var client = new RestClient("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1");
var request = new RestRequest(Method.GET);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
IRestResponse response = client.Execute(request);
MessageBox.Show(response.IsSuccessful.ToString());
I am not getting any response. Null Response.
error: InnerException = {“Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.”}
I tried another piece of code and got the same result.
private void GetAccountUsers(string ZoomApiKey, string ZoomApiSecret)
{
try
{
ZoomToken zt = new ZoomToken();
string Token = zt.GetToken(ZoomApiKey,ZoomApiSecret);
//Create new Request
string BaseUrl = "https://api.zoom.us/v2/users?status=active&page_size=300&page_number=1";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(BaseUrl);
myHttpWebRequest.Method = "GET";
myHttpWebRequest.ContentType = "application/json;";
myHttpWebRequest.Accept = "application/json;";
myHttpWebRequest.Headers.Add("Authorization", String.Format("Bearer {0}", Token));
//Get the associated response for the above request
//WHEN IT GETS HERE I GET AN ERROR. THE RESPONSE IN NULL.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
using (StreamReader MyStreamReader = new StreamReader(myHttpWebResponse.GetResponseStream(), true))
{
this.AccountUsers = JsonConvert.DeserializeObject<AccountUsers>(MyStreamReader.ReadToEnd());
}
myHttpWebResponse.Close();
myHttpWebResponse.Dispose();
}
catch (WebException ex)
{
int errorCode = (int)((HttpWebResponse)ex.Response).StatusCode;
if (errorCode != 0)
{
ErrorCode = errorCode;
Stream MyStream = ex.Response.GetResponseStream();
StreamReader MyStreamReader = new StreamReader(MyStream, true);
this.ZoomException = JsonConvert.DeserializeObject<ZoomErrorResponse>(MyStreamReader.ReadToEnd());
//would be nice to check ZoomException for Null before throwing
throw new Exception(this.ZoomException.Message);
}
}
}
jim.hubbard@UIH001900 MINGW64 /
$ % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 46 0 46 0 0 81 0 --:–:-- --:–:-- --:–:-- 81{“code”:124,“message”:“Invalid access token.”}