PowerShell 和 Google 日历 - 创建事件时出现 400 错误
PowerShell and Google Calendar - 400 Error when creating event
所以这将是第一次在 Google 开发论坛上发帖,祈祷我能解决这个问题,因为我正在拔头发!
我在 PowerShell 中有以下脚本。我已经对 OAuth2 进行了排序,我可以点击我的日历 API 并在仪表板中查看点击。所以,认证没问题。我使用 API Explorer 大致了解了我需要发送什么来创建一个新的日历事件,但在这样做时我收到了 400 错误。
这是我所在的部分 运行:
$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
这是我收到的错误:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
$json是这样构成的:
{
"end": "dateTime:2017-06-07T08:30:00+01:00",
"start": "dateTime:2017-06-07T08:00:00+01:00"
}
我可以删除 transferEncoding,但我得到了同样的错误。
一如既往,任何帮助都会很棒 :)
感谢
将我的评论移到答案中,-ContentType
看起来很奇怪,里面有一个反斜杠,也许它应该是一个正斜杠,例如
$json -ContentType 'application/json'
所以这将是第一次在 Google 开发论坛上发帖,祈祷我能解决这个问题,因为我正在拔头发!
我在 PowerShell 中有以下脚本。我已经对 OAuth2 进行了排序,我可以点击我的日历 API 并在仪表板中查看点击。所以,认证没问题。我使用 API Explorer 大致了解了我需要发送什么来创建一个新的日历事件,但在这样做时我收到了 400 错误。
这是我所在的部分 运行:
$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
这是我收到的错误:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
$json是这样构成的:
{
"end": "dateTime:2017-06-07T08:30:00+01:00",
"start": "dateTime:2017-06-07T08:00:00+01:00"
}
我可以删除 transferEncoding,但我得到了同样的错误。
一如既往,任何帮助都会很棒 :)
感谢
将我的评论移到答案中,-ContentType
看起来很奇怪,里面有一个反斜杠,也许它应该是一个正斜杠,例如
$json -ContentType 'application/json'