|
**Here is my request** var authHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}")); // Initialize HttpClient using var client = new HttpClient(); oauthUrl = oauthUrl + accountId; // Create request message var request = new HttpRequestMessage(HttpMethod.Post, oauthUrl); request.Headers.Add("Authorization", $"Basic {authHeader}"); // Send request and get response var response = await client.SendAsync(request); // Check if the request was successful (status code 200) if (response.IsSuccessStatusCode) { // Parse the JSON response to get the access token var jsonResponse = await response.Content.ReadAsStringAsync(); accessToken = JsonDocument.Parse(jsonResponse).RootElement.GetProperty("access_token").GetString(); // Meeting data var meeting_data = new JObject { { "topic", meetingRequest.Topic }, { "type", 2 }, { "start_time", meetingRequest.StartTime }, { "duration", meetingDuration }, { "password" ,"" }, {" agenda", meetingRequest.Topic }, { "pre_schedule" ,false }, { "timezone" ,meetingTimeZone }, { "default_password", true }, { "settings", new JObject { { "survey_url", "https://s.zoom.us/m/bPFbkCNPA" } }}, }; // Headers for the request var headers = new { Authorization = $"Bearer {accessToken}", Content_Type = "application/json", Accept = "application/json" // Send POST request to create meeting //var content = new StringContent(meeting_data.ToString(), Encoding.UTF8, "application/json"); using var meetingClient = new HttpClient(); using var mRequest = new HttpRequestMessage(HttpMethod.Post, apiUrl); mRequest.Content = new StringContent(meeting_data.ToString(), Encoding.UTF8, "application/json"); foreach (var header in headers.GetType().GetProperties()) { mRequest.Headers.Add(header.Name, header.GetValue(headers).ToString()); } var mResponse = await client.SendAsync(mRequest); // Return response try { var responseText = await mResponse.Content.ReadAsStringAsync(); var jObject = JObject.Parse(responseText); zmResponse.MeetingNumber = (string)jObject["id"]; zmResponse.Start_Url = (string)jObject["start_url"]; zmResponse.End_Url = (string)jObject["join_url"]; zmResponse.Status = "Success"; var zoom = new DTO.Zoom.Zoom() { CreatedBy = "", ModifiedBy = "", SessionId = meetingRequest.SessionId, StartUrl = zmResponse.Start_Url, JoinUrl = zmResponse.End_Url, MeetingNumber = zmResponse.MeetingNumber, }; await _iCoreFactory.IZoomService.Add(zoom); return zmResponse; } catch(Exception ex) { } return zmResponse; } else { zmResponse.Status = "Failed"; zmResponse.Message = response.StatusCode.ToString(); } (责任编辑:) |
