我正在尝试使用Google日历API来创建新日历。我在请求创建日历时遇到此错误。我在这里做错了什么:
Calendar newCalendar = new Calendar { Summary = "DropcueCalendar"};
string Url = "https://www.googleapis.com/calendar/v3/calendars";
HttpWebRequest request = HttpWebRequest.Create(Url) as HttpWebRequest;
string result = null;
request.Method = "POST";
request.KeepAlive = true;
request.Headers.Add("Authorization", "Bearer " + newToken.access_token);
string param = JsonConvert.SerializeObject(newCalendar);
byte[] bs = Encoding.ASCII.GetBytes(param);
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
}
// error occurring here during request.GetResponse() call
using (WebResponse response = request.GetResponse())
{
StreamReader sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
var data = JsonConvert.DeserializeObject(result);
sr.Close();
}
N.B:“newToken”是经过身份验证的令牌。