Google Calendar API clearing event location
I using the following code for changing Google Calendars Event's location:
EventEntry eventEntry = this.GetGoogleEvent(evt, cal);
eventEntry.Title.Text = evt.Summary开发者_运维技巧;
eventEntry.Locations.Clear();
if( NEWLOCATION != "" ) eventEntry.Locations.Add(new Where("", "", NEWLOCATION));
...
EventEntry newEvent = (EventEntry)eventEntry.Update();
It works fine, for changing the location, but nothing is updated when NEWLOCATION
is an empty string: ""
Any workaround? It's an API bug ?
Thanks for advices!
EDIT:
Also tried without if( NEWLOCATION != "" )
If you call Locations.Clear() and then Update(), you will be sending a PUT request without any gd:where elements. Update requests only update those fields that are specified in the request, so the gd:where elements of the event will be untouched.
If you want to clear the gd:where field of an event, you have to send an update request containing a single gd:where element whose value is an empty string. For instance, you may use the following code:
entry.Locations.Clear();
entry.Locations.Add(new Where());
entry.Update();
There was a bug in the library that was causing empty gd:where valueString elements to be ignored during update requests. This bug was fixed a few minutes ago in rev. 1113 of the library:
http://code.google.com/p/google-gdata/source/detail?r=1113
For starters, I would compare against empty string:
if( NEWLOCATION != string.Empty )
{
eventEntry.Locations.Add(new Where("", "", NEWLOCATION));
}
Also I would always use brackets, just to make sure that I know what will be executed if condition is matched.
As for empty location, I might be fundamentally wrong here but isn't the Locations.Clear() method already setting Locations to empty values? Isn't it accepted? Maybe you would need two separate updates one for clearing the location and another one to change other values?
精彩评论