2012-03-25 35 views
2

我试图将我的webapp的日历与Google日历集成。我正在成功验证用户身份,能够从Google读取事件并从Google中删除事件。我在从我的应用更新事件到Google时遇到问题。Google Calendar API - PATCH返回200正常但未实际更新事件

我使用补丁的方法描述 here我只是想修改我的API调用发送(而不是在PUT调用,它需要对这一事件的所有字段)的字段。

我的Perl代码创建了一个JSON对象来表示我想要更改的内容。然后我向Google提交PATCH请求,并且我收到状态200 OK并从Google返回事件资源。我收到的回应应该是修改的事件资源,但是我修改的字段在响应中未被修改。当我检查Google日历本身时,我再次看到该事件未被修改。

我很困惑,为什么当事件没有更新时,我得到200 OK响应而不是错误。奇怪的是,在响应中,“更新”时间戳记属性已更新,但汇总字段没有更新。

my $ua = LWP::UserAgent->new; 

    my $url = "https://www.googleapis.com/calendar/v3/calendars/primary/events/${id}?access_token=${access_token}"; 

    my $resource{"summary"} = "$g{summary}"; 

    $resource = encode_json(\%resource); 

    my $headers = HTTP::Headers->new(); 
    $headers->header(If_Match => "$etag"); 

    my $request = HTTP::Request->new('PATCH',$url,$headers,$resource); 

    my $response = $ua->request($request); 

    my $status = $response->status_line; 

    my $result = decode_json($response->decoded_content); 

从结果“ETAG”值如我所料,这表明日历事件正在(有点)修改谷歌更新。

一些数据::自卸车跟踪:

请求:

$VAR1 = bless({ 
       '_content' => '{"summary":"End of season function MODIFIED"}', 
       '_uri' => bless(do{\(my $o = 'https://www.googleapis.com/calendar/v3/calendars/primary/events/<eventID>?access_token=<access_token>')}, 'URI::https'), 
       '_headers' => bless({ 
             'if-match' => '<etag>' 
             }, 'HTTP::Headers'), 
       '_method' => 'PATCH' 
       }, 'HTTP::Request'); 

响应:

$VAR1 = bless({ 
       '_protocol' => 'HTTP/1.1', 
       '_content' => '{ 
"kind": "calendar#event", 
"etag": "<etag>", 
"id": "<eventID>", 
"status": "confirmed", 
"htmlLink": "<suppressed>", 
"created": "2012-03-08T05:06:04.000Z", 
"updated": "2012-03-25T09:18:49.000Z", 
"summary": "End of season function", 
"creator": { 
    "email": "<suppressed>" 
}, 
"organizer": { 
    "email": "<suppressed>" 
}, 
"start": { 
    "date": "2012-03-24" 
}, 
"end": { 
    "date": "2012-03-24" 
}, 
"iCalUID": "<suppressed>", 
"sequence": 1, 
"reminders": { 
    "useDefault": true 
} 
} 
', 
       '_rc' => '200', 
       '_headers' => bless({ 
             'connection' => 'close', 
             'cache-control' => 'no-cache, no-store, max-age=0, must-revalidate', 
             'date' => 'Sun, 25 Mar 2012 09:18:49 GMT', 
             'client-ssl-cert-issuer' => '/C=US/O=Google Inc/CN=Google Internet Authority', 
             'client-ssl-cipher' => 'ECDHE-RSA-RC4-SHA', 
             'client-peer' => '173.194.72.95:443', 
             'client-date' => 'Sun, 25 Mar 2012 09:18:49 GMT', 
             'pragma' => 'no-cache', 
             'content-type' => 'application/json; charset=UTF-8', 
             'x-xss-protection' => '1; mode=block', 
             'server' => 'GSE', 
             'client-ssl-socket-class' => 'IO::Socket::SSL', 
             'client-response-num' => 1, 
             'etag' => '<etag>', 
             'x-frame-options' => 'SAMEORIGIN', 
             'x-content-type-options' => 'nosniff', 
             'client-ssl-cert-subject' => '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com', 
             'expires' => 'Fri, 01 Jan 1990 00:00:00 GMT' 
             }, 'HTTP::Headers'), 
       '_msg' => 'OK', 
       '_request' => bless({ 
             '_content' => '{"summary":"End of season function MODIFIED"}', 
             '_uri' => bless(do{\(my $o = 'https://www.googleapis.com/calendar/v3/calendars/primary/events/<eventID>?access_token=<access_token>')}, 'URI::https'), 
             '_headers' => bless({ 
                   'user-agent' => 'libwww-perl/6.01', 
                   'if-match' => '<etag>' 
                  }, 'HTTP::Headers'), 
             '_method' => 'PATCH', 
             '_uri_canonical' => $VAR1->{'_request'}{'_uri'} 
             }, 'HTTP::Request') 
       }, 'HTTP::Response'); 

有人能看到我在做什么错?我确信Google正在接受我的PATCH请求,但由于某种原因我没有看到我想要修改的字段。我已经尝试在其testing page上提交完全相同的JSON对象,并且没有问题使其工作...

回答

3

我发现解决方案纯粹是通过试验和错误 - 将“Content-Type”标头添加到HTTP标头似乎做的伎俩:

my $headers = HTTP::Headers->new(); 
    $headers->header(If_Match => "$etag"); 
    $headers->header(Content_Type => "application/json"); 
相关问题