Google Calendar API : event description in HTML

2019-08-13 23:39发布

问题:

I'm inserting the event into Google calendar and I can't find the way I can specify that description is not a plain text but the HTML markup:

request = WebRequest.Create("https://www.googleapis.com/calendar/v3/calendars/" + calendarID + "/events?pp=1&key=" + ClientID) as HttpWebRequest;
request.Headers.Add("Accept-Charset", "utf-8");
request.KeepAlive = true;
request.ContentType = "application/json";
request.Method = "POST";
request.Headers.Add("Authorization", "OAuth " + googleToken.ToString());
var actEvent = new GoogleCalendarEvent
    {
    summary = eventCalendar.Title,
    description = eventCalendar.Description,
    start = new GoogleCalendarEventTime(eventCalendar.Date),
    end = new GoogleCalendarEventTime(eventCalendar.Date.AddHours(1))
};

var data = jsonSerializer.Serialize(actEvent);
var postData = Encoding.UTF8.GetBytes(data);
Stream ws = request.GetRequestStream();
ws.Write(postData, 0, postData.Length);
ws.Close();
response = request.GetResponse();
stream = new StreamReader(response.GetResponseStream());
var result = stream.ReadToEnd().Trim();

return Json(new {Success = true});

回答1:

If you go to the documentation here, it speaks of setting the type (MIME). This means you probably just have to set the type to HTML.



回答2:

There is only plain text available for Google Calendar Event description field. :-(



回答3:

put description in a variable like this:

$variable = [
             "<span>Text here</span> <br/>
              <b>Text here</>
               ...           "
            ];