KEN-gie
KEN-gie
CC#
Created by KEN-gie on 1/4/2023 in #help
❔ System.Net.Http truncates one of the response attributes
The access_token is always 632 characters long, and when I test it in Postman it works fine Postman Code: using System; using RestSharp; namespace HelloWorldApplication { class HelloWorld { static void Main(string[] args) { var client = new RestClient("https://zoom.us/oauth/token?account_id=VfdA06Q9TQe31jH7oRutuQ&grant_type=account_credentials"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Basic ####"); request.AddHeader("Cookie", "####"); var body = @""; request.AddParameter("text/plain", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); } } } I have a limitation that prevents me from using RestSharp. As such, I am using System.Net.Http in my application, but the access_token is always 533 characters long. I get unauthorized response whenever I use that token which is what alerted me that something may be wrong with it. System.Net.Http Code using System; using System.Collections.Generic; using System.Net.Http; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace ConsoleApp_Test_ZoomCreateMeeting { class Program { static void Main(string[] args) { //Get current token age
// Get the get credentials // Build the request body var authRequestBody = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("grant_type", "client_credentials"), new KeyValuePair<string, string>("client_id", "####"), new KeyValuePair<string, string>("client_secret", "####") }); // Set up the HTTP client var authClient = new HttpClient(); authClient.BaseAddress = new Uri("https://zoom.us/"); // Send the request and get the response HttpResponseMessage authResponse = authClient.PostAsync("oauth/token", authRequestBody).Result; string content = authResponse.Content.ReadAsStringAsync().Result; long contentLength = authResponse.Content.Headers.ContentLength ?? 0; string responseContent = authResponse.Content.ReadAsStringAsync().Result; // Parse the JSON response JObject jsonResponse = JsonConvert.DeserializeObject<JObject>(responseContent); // Create an instance of JsonSerializerSettings and set the ReferenceLoopHandling property to Ignore JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); serializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // Serialize the jsonResponse object using the JsonSerializerSettings object string serializedJsonResponse = JsonConvert.SerializeObject(jsonResponse, serializerSettings); // Extract the access_token property (value<t>) string currentToken = jsonResponse["access_token"].Value<string>();
Console.WriteLine("Current Token: " + currentToken);

} } } Any ideas on a solution here? I tried to request an OAuth token from the Zoom API, and though I received one, the access_token attribute is being cut short c#zoom-sdk
4 replies