2017-10-07 41 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

我仍然得到你的代码错误请求 –