Updating Calendar Event Giving Error “The specified value is not a valid quoted string”

心已入冬 提交于 2019-12-11 04:08:34

问题


As of today we are getting an error when we try to update an event using Google Calendar V3 API.

Here is our code:

    string certificateFile = getCertificateFile();
    string certificatePassword = getCertificatePassword();
    string serviceAccountEmail = getServiceAccountEmail();

    X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.Exportable);

    ServiceAccountCredential credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = new[] { Google.Apis.Calendar.v3.CalendarService.Scope.Calendar },
        User = user
    }.FromCertificate(certificate));

    Google.Apis.Calendar.v3.CalendarService service = new Google.Apis.Calendar.v3.CalendarService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "Test",
    });

    try
    {
        Event evv = service.Events.Get(user, "6ebr4dp452m453n468movuntag").Execute();
        EventsResource.UpdateRequest ur = new EventsResource.UpdateRequest(service, evv, user, evv.Id);
        ur.Execute();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }

The Error message is " The specified value is not a valid quoted string. "

This is basic code that always works. We can still query and insert Events. For some reason updates have just stopped working?

Anybody else getting this?


回答1:


I found what is the problem: Google API's ETag functionality seems to be broken.

To get around the issue I had to download the source code of the .NET Google API client libraries from google-api-dotnet-client Downloads and commented the call to the method AddETag() on line 189 of ClientServiceRequest.cs; that method adds the If-Match ETag header that's currently causing the issues. This file is in the GoogleApis project.

    public HttpRequestMessage CreateRequest(Nullable<bool> overrideGZipEnabled = null)
    {
        var builder = CreateBuilder();
        var request = builder.CreateRequest();
        object body = GetBody();
        request.SetRequestSerailizedContent(service, body, overrideGZipEnabled.HasValue
            ? overrideGZipEnabled.Value : service.GZipEnabled);

        //AddETag(request);
        return request;
    }

See Protocol Reference: Updating Entries for more information on how Google API's use ETags and the If-Match header.




回答2:


The problem in the Calendar API was fixed so no need to use this workaround!

Please don't use the above suggestion. Although it works, it will actually eliminate an important feature of etag in the library. A better solution is available at: https://codereview.appspot.com/96320045/

Thanks diegog for your work-around, I'm pretty sure it helped several users who were stuck today.



来源:https://stackoverflow.com/questions/23649831/updating-calendar-event-giving-error-the-specified-value-is-not-a-valid-quoted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!