2013-06-18 15 views
5

プライマリカレンダーから空き時間をすべて検索しようとしていますが、パラメータを認識できるようにクエリを取得できません。Google freebusy api call in railsがパラメータを認識しない

私は私のコントローラで

@freetimes = client.execute(
    :api_method => service.freebusy.query, 
    :parameters => { 
    'timeMin' => '2013-06-15T17:06:02.000Z', 
    'timeMax' => '2013-06-29T17:06:02.000Z', 
    'items' => [{'id' => '[email protected]'}] 
    }, 
    :headers => {'Content-Type' => 'application/json'}) 

私が得る応答は次のとおりです。

--- !ruby/object:Google::APIClient::Schema::Calendar::V3::FreeBusyResponse 
data: 
error: 
    errors: 
    - domain: global 
     reason: required 
     message: Missing timeMin parameter. 
    code: 400 
    message: Missing timeMin parameter. 

は、しかしである、それはパラメータを取ったことを示しているが、彼らは、クエリに接続されていませんでした:

--- !ruby/object:Google::APIClient::Result 
request: !ruby/object:Google::APIClient::Request 
    parameters: 
    timeMin: '2013-06-15T17:06:02.000Z' 
    timeMax: '2013-06-29T17:06:02.000Z' 
    items: 
    - id: [email protected] 

これを解決する助けがあれば幸いです!

+0

レスポンスに基づいて解決しました[1] 他のカレンダーメソッドとは違って、正しく渡すためにはJSONにする必要がありました。 [1]:http://stackoverflow.com/questions/7455744/post-json-to-api-using-rails-and-httparty – tristantoye

答えて

6

私は同様の問題を抱えていたリクエストボディ

client.execute(
    :api_method => service.freebusy.query, 
    :body => JSON.dump({ 
    :timeMin => , 
    :timeMax => , 
    :items => 
    }), 
    :headers => {'Content-Type' => 'application/json'}) 
1

を指定することによって、これを解決しました。代わりに、あなたはFreeBusyRequestオブジェクトを構築することができます。このよう

body = Google::Apis::CalendarV3::FreeBusyRequest.new 
body.items = [calendar_id] 
body.time_min = "2016-06-29T13:00:00z" 
body.time_max = "2016-06-29T21:00:00z" 
body 

`` ` 、その後、あなたは、このようなCalendarServiceオブジェクトにそれを渡すことができます:

service = Google::Apis::CalendarV3::CalendarService.new 
service.authorization = client 
service.query_freebusy(body) 

が、これは間違いなく、本体と、ステータス200レスポンスを返します。

関連する問題