Google Calendar API-PATCH返回200 OK,但实际上没有更新事件

问题描述 投票:2回答:2

我正在尝试将Webapp的日历与Google日历集成。我已成功验证用户身份,能够从Google读取事件并从Google删除事件。我无法将事件从我的应用更新到Google。

我正在使用 here中描述的PATCH方法,因为我只想修改在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”值会按预期更新,这表明日历事件正在(某种程度上)在Google中进行了修改。

某些数据::倾销者跟踪:

请求:

$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对象,并且使其正常工作没有问题...

我正在尝试将Webapp的日历与Google日历集成。我已成功验证用户身份,能够从Google读取事件并从Google删除事件。我有麻烦...

perl google-api google-calendar-api
2个回答
3
投票

我纯粹是通过反复试验找到了解决方案-在HTTP标头中添加“ Content-Type”标头似乎可以解决问题:


0
投票

我正在使用Content-Type,但是没有达到目的。

© www.soinside.com 2019 - 2024. All rights reserved.