2011-12-19 18 views
3

私はGoogleカレンダーを更新する必要のあるアプリを開発中です。で、Googleカレンダーのデベロッパーガイドに従うことによりGoogle Calendar Ruby API

:私もevent.to_json行うことを試みた

TypeError (Expected body to respond to :each.): 

http://code.google.com/apis/calendar/v3/using.html#creating_events

event = { 
    'summary' => 'Appointment', 
    'location' => 'Somewhere', 
    'start' => { 
    'dateTime' => '2011-06-03T10:00:00.000-07:00' 
    }, 
    'end' => { 
    'dateTime' => '2011-06-03T10:25:00.000-07:00' 
    } 
} 
result = client.execute(:api_method => service.events.insert, 
        :parameters => {'calendarId' => 'primary'}, 
        :body => JSON.dump(event), 
        :headers => {'Content-Type' => 'application/json'}) 

私は次のエラーを取得します。

答えて

5

私の頭の上からほんの2つの提案が参考になるかもしれません。これらを試してみてください。配列へ

ラップ:body

result = client.execute(:api_method => service.events.insert, 
        :parameters => {'calendarId' => 'primary'}, 
        :body => [JSON.dump(event)], 
        :headers => {'Content-Type' => 'application/json'}) 

、体の代わりに:body_objectを使用し、eventハッシュjsonifyません:

result = client.execute(:api_method => service.events.insert, 
        :parameters => {'calendarId' => 'primary'}, 
        :body_object => event, 
        :headers => {'Content-Type' => 'application/json'}) 

http://code.google.com/p/google-api-ruby-client/source/browse/lib/google/api_client/reference.rbを見て、あなたが理解してますがどのように私はこれらの提案を思い付いた。

+0

両方の提案が有効です。ありがとう。 – y4ku