2017-10-07 114 views
0

因爲我有工作的OAuth和可以得到的PowerShell原生谷歌CAL條目是這樣的:谷歌日曆插頁的PowerShell

$from=$((Get-Date).adddays(-1)).ToString("yyyy-MM-ddTHH:mm:ss-ff:ff") 
$to=$((Get-Date).adddays(+7)).ToString("yyyy-MM-ddTHH:mm:ss-ff:ff") 
$Events = Invoke-RestMethod -Uri ` 
"https://www.googleapis.com/calendar/v3/calendars/$calid/events?access_token=$accesstoken&timeMin=$from&timeMax=$to" 

我現在正在試圖找出如何做插入和真的不知道如何告訴API我想要做的插入:

$NewEvent = @{ 
    summary="Google I/O 2015"; 
    location="800 Howard St., San Francisco, CA 94103"; 
    description="A chance to hear more about Google developer products."; 
    start = @{ 
    date_time ="2017-10-09T09:00:00-07:00"; 
    time_zone =" ''America/Los_Angeles''"; 
    } 
    } 

$ReturnI = Invoke-RestMethod -Uri ` 
"https://www.googleapis.com/calendar/v3/calendars/$calid/events?access_token=$accesstoken&Method=insert" -Method Get -body $NewEvent 

我的問題是因此一)有我犯了一個有效的$ NewEvent和b)我怎麼做一個Invoke-RestMethod到coraspond到谷歌的API方法?

感謝

+3

你可能不得不改變方法發佈 –

回答

0

使用調用-RestMethod這樣,而不是:

$requestUri = "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?" 

[email protected]{ 
end='dateTime:2017-06-07T08:30:00+01:00' 
start='dateTime:2017-06-07T08:00:00+01:00' 
} 

$json = $body | ConvertTo-Json 
[email protected]{Authorization = "Bearer $($tokens.access_token)"} 

Invoke-RestMethod -Headers $header -Uri $requestUri -Method POST -Body 
$json -ContentType 'application/json' 
+0

我仍然得到你的代碼錯誤請求 –