I am trying to perform a PUT to Google Calendar API v3 in order to add an attendee, but every time I get the response 400 BAD REQUEST. I have simplified it to just attempt to update the max number of attendees to see if it will take, but no dice...
public void AddAttendeeToEvent(string calendarId, string eventId, string attendeeEmail)
{
try
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + AuthenticationHelper.Instance.Token);
var baseUrl = String.Format("https://www.googleapis.com/calendar/v3/calendars/{0}/events/{1}", calendarId, eventId);
//var postData = string.Format ("attendees[].email={0}", attendeeEmail);
var postData = "maxAttendees=100";
var content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
var response = httpClient.PutAsync(baseUrl, content).Result;
response.EnsureSuccessStatusCode ();
}
catch(Exception ex)
{
string s = "";
}
}
Note - This is in Xamarin, there is no client library available. Has to be done manually for now...and the documentation on this is horrible.
I propose you drop this code and start over using C# Calendar API client library. You can get it from the downloads in the documentation page: https://developers.google.com/google-apps/calendar/
However, as the first step, please read the getting started guidelines and obtain a correct Oauth2 token.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.