2013-06-18 33 views
5

我想從我的主日曆中找到所有freebusy時間,但我無法獲得查詢來識別我的參數。谷歌的freebusy API調用不會識別參數

在我的控制,我有:

@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響應。