且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法写入Google表格((400)Bad Request)

更新时间:2023-01-03 18:47:12

Your Invoke-WebRequest is missing the ContentType parameter, which is necessary when your Method is set to a verb for sending data (such as Post).

The purpose of the Content-Type field is to describe the data contained in the body fully enough that the receiving user agent can pick an appropriate agent or mechanism to present the data to the user, or otherwise deal with the data in an appropriate manner.

The Content-Type Header Field

In your case, the parameter will be -ContentType "application/json". For example:

Invoke-WebRequest -Uri "https://sheets.googleapis.com/v4/spreadsheets/$sheet/values/Sheet1!A1:D2:append?valueInputOption=USER_ENTERED&access_token=$($token.access_token)" -Method Post -ContentType "application/json" -Body $json 

Invoke-WebRequest ContentType Documentation

相关阅读

技术问答最新文章