'Google API Calendar OAUTH2 The remote server returned an error: (404) Not Found

async void GetEvent(string access_token) {
    String serviceURL = "https://www.googleapis.com/calendar/v3/calendars/{email}/events";
    String url = string.Format(serviceURL + "&key={0}&scope={1}", clientSecret, "https://www.googleapis.com/auth/calendar.events.readonly");

    // sends the request
    HttpWebRequest userinfoRequest = (HttpWebRequest)WebRequest.Create(url);
    userinfoRequest.Method = "GET";
    userinfoRequest.Headers.Add(string.Format("Authorization: Bearer {0}", access_token));
    userinfoRequest.ContentType = "application/json";
    userinfoRequest.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    userinfoRequest.UseDefaultCredentials = true;
    userinfoRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // gets the response
    WebResponse userinfoResponse = await userinfoRequest.GetResponseAsync();
    using (StreamReader userinfoResponseReader = new StreamReader(userinfoResponse.GetResponseStream())) {
        // reads response body
        string userinfoResponseText = await userinfoResponseReader.ReadToEndAsync();
        output(userinfoResponseText);
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source