Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top