PowerShell和Google日历 - 400创建活动时出错

时间:2017-06-07 16:59:00

标签: powershell calendar google-calendar-api

所以这将是第一次在谷歌开发论坛上发帖,手指交叉我可以解决这个问题,因为我要把头发拉出来!

我在PowerShell中有以下脚本。我已经对OAuth2进行了排序,我可以点击我的Calendar API并查看仪表板中的匹配。因此,身份验证很好。我使用API​​ Explorer大致了解了为了创建一个新的Calendar事件我需要发送什么,但是这样做我得到400错误。

这是我正在运行的部分:

FirebaseDatabase.getReference("orders").orderByChild("firebaseId").equalTo(firebaseUser.uid).keepSynced(true)
FirebaseDatabase.getReference("orderItems").orderByChild("firebaseId").equalTo(firebaseUser.uid).keepSynced(true)

以下是我收到的错误:

$requestUri = "https://www.googleapis.com/calendar/v3/calendars/mysite@blah.com/events?"

$body=@{
end='dateTime:2017-06-07T08:30:00+01:00'
start='dateTime:2017-06-07T08:00:00+01:00'
}


$json = $body | ConvertTo-Json

$header=@{Authorization = "Bearer $($tokens.access_token)"}

Invoke-RestMethod -Headers $header -Uri $requestUri -Method POST -Body 
$json -ContentType 'application\json' -TransferEncoding gzip

$ json就是这样形成的:

 Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

我可以删除transferEncoding,但我得到同样的错误。

与往常一样,任何帮助都会很棒:)

谢谢

1 个答案:

答案 0 :(得分:1)

将我的评论移到答案中,-ContentType看起来很奇怪,其中有反斜杠,也许它应该是正斜杠,例如。

$json -ContentType 'application/json'