My Error showing code
private async Task S2SOauth()
{
// Access the environment variables
var clientId = “”;
var clientSecret = “”;
var accountId = “”;
var oauthUrl = $“https://zoom.us/oauth/token?grant_type=account_credentials&account_id={accountId}”;
// Create the Basic Authentication header
var authHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));
// Initialize HttpClient
using var client = new HttpClient();
// Create request message
var request = new HttpRequestMessage(HttpMethod.Post, oauthUrl);
request.Headers.Add("Authorization","Basic "+authHeader);
//var request = request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authHeader);
//var http = new HttpClient();
//http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "key=XXX");
// Send request and get response
var response = await client.SendAsync(request);
// Check if the request was successful (status code 200)
// Parse the JSON response to get the access token
var jsonResponse = await response.Content.ReadAsStringAsync();
var accessToken = JsonDocument.Parse(jsonResponse).RootElement.GetProperty("access_token").GetString();
var json = Newtonsoft.Json.JsonConvert.SerializeObject(accessToken);
return json;
// Set the "Content-Type" header to "application/json"
//await context.Response.WriteAsync(JsonConvert.SerializeObject(accessToken));
}
public async Task CallAPI()
{
var accessToken1 = S2SOauth();
// Fetch access_token from query string
var access_token = accessToken1;
// Meeting data
var meeting_data = new
{
topic = "hello world",
type = 2,
start_time = DateTime.UtcNow.AddMinutes(10).ToString("yyyy-MM-ddTHH:mm:ssZ"), // Start time in UTC
duration = 120,
password = "12345678",
agenda = "40 mins limit demonstration",
pre_schedule = false,
timezone = "Asia/Singapore",
default_password = false
};
// Zoom API endpoint
var api_url = "https://api.zoom.us/v2/users/me/meetings";
// Headers for the request
var headers = new
{
Authorization = $"Bearer {access_token}",
Content_Type = "application/json",
Accept = "application/json"
};
// Send POST request to create meeting
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, api_url);
request.Content = new StringContent(JsonSerializer.Serialize(meeting_data), Encoding.UTF8, "application/json");
foreach (var header in headers.GetType().GetProperties())
{
request.Headers.Add(header.Name, header.GetValue(headers).ToString());
}
var response = await client.SendAsync(request);
var result = "Meeting Details: "+await response.Content.ReadAsStringAsync();
// Return response
//await context.Response.WriteAsync("Meeting Details: " + await response.Content.ReadAsStringAsync());
return RedirectToAction("Index");
}
And I got the below error from this code
FormatException: The format of value ‘Bearer System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox
1[System.String,ZoomMeeting_API.Controllers.HomeController+d__5]’ is invalid.