使用Google Calendar API创建监视我的日历时出错 - 错误的请求

时间:2017-03-07 05:52:09

标签: google-calendar-api

我正在尝试使用Google Calendar API为我的日历创建一个Watch ...但是当我尝试创建它时会抛出异常“远程服务器返回错误:(400)错误请求。”

以下是我的代码:

        HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/calendar/v3/calendars/floristpanel@gmail.com/events/watch");
        request1.Method = "POST";

        request1.Headers.Add("Authorization", "Bearer " + accesstoken);
        request1.ContentType = "application/json";

        string postData1 = "type=web_hook&id=01234567-89ab-cdef-0123456789ab&address=https://www.hanafloralpos.com/notification.aspx";
        byte[] bytes1 = Encoding.UTF8.GetBytes(postData1);
        request1.ContentLength = bytes1.Length;

        Stream requestStream1 = request1.GetRequestStream();
        requestStream1.Write(bytes1, 0, bytes1.Length);

        WebResponse response1 = request1.GetResponse();
        Stream stream1 = response1.GetResponseStream();
        StreamReader reader1 = new StreamReader(stream1);

        var result1 = reader1.ReadToEnd();
        stream1.Dispose();
        reader1.Dispose();

0 个答案:

没有答案