2012-03-25 1 views
2

私はwebappのカレンダーとGoogleカレンダーを統合しようとしています。私は正常にユーザーを認証し、Googleからイベントを読み取り、Googleからイベントを削除することができます。アプリからGoogleにイベントを更新する際に問題が発生しています。Google Calendar API - 200 OKを返すが実際にはイベントを更新しないパッチ

hereに記載されているPATCHメソッドを使用しています。私は、(イベントのすべてのフィールドを必要とするPUT呼び出しとは対照的に)API呼び出しで送信するフィールドを変更したいだけです。

私の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で(多少)変更されていることを示しています。

いくつかのデータ:: Dumperをトレース:

を要求:

$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

純粋に試行錯誤で解決策を見つけました.HTTPヘッダーに「Content-Type」ヘッダーを追加しましたトリックをするように見えた:

my $headers = HTTP::Headers->new(); 
    $headers->header(If_Match => "$etag"); 
    $headers->header(Content_Type => "application/json"); 
関連する問題