Use .net nuget JWT calling API2 return 401


#1

there is the code:

private static readonly string Key = “xxxxx”;
private static readonly string Secret = “xxxxxx”;
private static string GetToken()
{
var token = new { iss=Key,exp=Common.Utils.TimeStamp+5000};
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
return new JwtEncoder(algorithm,serializer,urlEncoder).Encode(token, Secret);
}
public static string GetZoomUser()
{
var url = “https://api.zoom.us/v2/accounts”;
var token = GetToken();
var getString = “access_token=” + token;
var header = new Dictionary<string, string>();
header.Add(“Authorization”,“Bearer” + token);
var result= HttpGet(url, getString, header);
return result;
}

 

public static string HttpGet(string Url, string postDataStr,Dictionary<string,string> Header)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == “” ? “” : “?”) + postDataStr);
request.Method = “GET”;
request.ContentType = “text/html;charset=UTF-8;”;
foreach (var header in Header)
{
request.Headers.Add(header.Key, header.Value);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding(“utf-8”));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();

return retString;
}

I have Key and Secret.


#2

 I got answer,because I’m not pay money


#3

Hi Curious, 

Thanks for letting us know that you figured out your issue.