asp.net 在Google日历中使用Google Meet链接创建活动-正在创建活动,但创建会议时出错

huwehgph  于 2023-07-01  发布在  .NET
关注(0)|答案(1)|浏览(162)
  • 你好,* 我试图通过创建一个谷歌事件谷歌会议链接.NET应用程序,

令牌生成和事件创建部分工作正常,但满足创建部分显示错误,这里是必需的代码,
在控制器中,

if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var jsonObject = JObject.Parse(response.Content);
                var id = (string)jsonObject["id"];
                var createdEvent = JsonConvert.DeserializeObject<Event>(response.Content);
                //string meetingLink = createdEvent.ConferenceData.EntryPoints[0].Uri;
                // Create a conference for the event
                var conferenceRequest = new CreateConferenceRequest();
                //pass RequestId
                var Id = conferenceRequest.RequestId;
                var conferenceModel = JsonConvert.SerializeObject(conferenceRequest, new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });

                var conferenceRequestUrl = $"https://www.googleapis.com/calendar/v3/calendars/primary/events/{id}/createConference";
                var conferenceRequestRestClient = new RestClient(conferenceRequestUrl);
                var conferenceRequestRestRequest = new RestRequest(Method.POST);
                conferenceRequestRestRequest.AddHeader("Authorization", "Bearer " + tokens["access_token"]);
                conferenceRequestRestRequest.AddHeader("Accept", "application/json");
                conferenceRequestRestRequest.AddHeader("Content-Type", "application/json");
                conferenceRequestRestRequest.AddParameter("application/json", conferenceModel, ParameterType.RequestBody);

                var conferenceRequestResponse = conferenceRequestRestClient.Execute(conferenceRequestRestRequest);
                if (conferenceRequestResponse.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var conferenceResponseContent = JObject.Parse(conferenceRequestResponse.Content);
                    var conferenceData = conferenceResponseContent["conferenceData"];
                    var meetLink = conferenceData?["entryPoints"]?.FirstOrDefault(x => x["entryPointType"].ToString() == "video")?["uri"]?.ToString();

                    if (!string.IsNullOrEmpty(meetLink))
                    {
                        // Do something with the meetLink (e.g., store it, display it, etc.)
                    }

                    return RedirectToAction("Index", "Home", new { status = "Success" });
                }

            }
In model
public class CreateConferenceRequest
        {
            public CreateConferenceRequest()
            {
                RequestId = Guid.NewGuid().ToString(); // Generate a unique request ID
                ConferenceSolutionKey Cf = new ConferenceSolutionKey();
                {
                    Cf.Type = "hangoutsMeet"; // Use Google Meet as the conference solution
                };
            }

            public string RequestId { get; set; }


            public class ConferenceSolutionKey
            {
                public string Type { get; set; }
            }
        }

Copyright © 2018 www.googleapis.com.cn All Rights Reserved.粤ICP备15037552号-1 *
如果有人有关于这个问题的想法或资源,请分享。

hivapdat

hivapdat1#

这可能是你得到错误的原因:Id应为id

var id = conferenceRequest.RequestId; // Id should be id
    var conferenceRequestUrl = $"https://www.googleapis.com/calendar/v3/calendars/primary/events/{id}/createConference";```

相关问题