使用google calendar api v3插入日历时出现此错误:远程服务器返回错误:(400)错误请求

时间:2014-02-03 13:50:54

标签: oauth-2.0 google-calendar-api

我正在尝试使用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”是经过身份验证的令牌。

0 个答案:

没有答案