❔ 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
// 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
3 Replies
first of all: use $code to properly format your code examples
also what framework/vs are you on, that you are not using async/await :/
for the actual problem: i dont see anything obvious, but some things come to mind:
1.
authClient.BaseAddress = new Uri("https://zoom.us/%22);
doesn't compile ... you somehow url-encoded the closeing "
2. the two examples do quite obviously different stuff (differnet querystrings, headers, bodys)
3. you deserialize the response content and serialize it back, but don't use the re-serialized string any further (shouldn't be a problem but it's best to provide minimal examples so people dont get confused)
4. have you checked if responseContent
contains the whole response? since it seems to be json it should be easy to see if the response is cut of somewhere
is the access_token in responseContent
the same you get from jsonResponse["access_token"].Value<string>()
?To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.