使用 javascript 将数据插入 Google 工作表 API
Inserting Data's Into Google Sheets API Using javascript
我正在尝试将我的数据插入 google Sheet API。所以我跟着这个 Link
在我的控制台中尝试 PUT 400()
后没有出现错误,
在我的 Network Header
Request URL:https://sheets.googleapis.com/v4/spreadsheets/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/values/Sheet1!A1:B1?valueInputOption==USER_ENTERED
Request Method:PUT
Status Code:400
Remote Address:74.125.68.95:443
我的网络响应是
{
"error": {
"code": 400,
"message": "Invalid value at 'value_input_option' (TYPE_ENUM), \"=USER_ENTERED\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "value_input_option",
"description": "Invalid value at 'value_input_option' (TYPE_ENUM), \"=USER_ENTERED\""
}
]
}
]
}
}
。我在这里做错了什么,或者我仍然必须在我的代码中添加东西? .有人可以 Help/Clarify 我。这是我的 HTML ,
<div ng-controller="BasicExampleCtrl">
<header data-ng-include="'app/views/header.html'"></header>
<div class="header" data-ng-include="'app/views/menu.html'"></div>
<h2>Welcome Google SpreadSheet Page</h2>
<button class="btn btn-primary"
data-ng-click="read()" style="position: absolute;width: 199px;height: 35px;left: 0px;top: 190px;">View In GoogleSheets</button>
</div>
<iframe id='ifr' src='https://docs.google.com/spreadsheets/d/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/edit#gid=0'
style="position: absolute;width: 100%;height: 100%;left: 0px;top: 250px;" >
</iframe>
<iframe id='ifr' src='https://docs.google.com/spreadsheets/d/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/edit#gid=0'style="position: absolute;width: 100%;height: 100%;left: 0px;top: 250px;" >
</iframe>
这是我的 Js 代码,
$scope.read = function () {
var params = {
"range":"Sheet1!A1:B1",
"majorDimension": "ROWS",
"values": [
["Hello","World"]
],
}
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://sheets.googleapis.com/v4/spreadsheets/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/values/Sheet1!A1:B1?valueInputOption==USER_ENTERED;headers=false');
xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
xhr.send(JSON.stringify(params));
};
}]);
您有 valueInputOption==USER_ENTERED
而不是 valueInputOption=USER_ENTERED
。两个等号而不是一个。错误消息告诉您相同的信息:"Invalid value at 'value_input_option' (TYPE_ENUM), \"=USER_ENTERED\""
-- =USER_ENTERED
不是有效值,但 USER_ENTERED
是。
我正在尝试将我的数据插入 google Sheet API。所以我跟着这个 Link
在我的控制台中尝试 PUT 400()
后没有出现错误,
在我的 Network Header
Request URL:https://sheets.googleapis.com/v4/spreadsheets/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/values/Sheet1!A1:B1?valueInputOption==USER_ENTERED
Request Method:PUT
Status Code:400
Remote Address:74.125.68.95:443
我的网络响应是
{
"error": {
"code": 400,
"message": "Invalid value at 'value_input_option' (TYPE_ENUM), \"=USER_ENTERED\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "value_input_option",
"description": "Invalid value at 'value_input_option' (TYPE_ENUM), \"=USER_ENTERED\""
}
]
}
]
}
}
。我在这里做错了什么,或者我仍然必须在我的代码中添加东西? .有人可以 Help/Clarify 我。这是我的 HTML ,
<div ng-controller="BasicExampleCtrl">
<header data-ng-include="'app/views/header.html'"></header>
<div class="header" data-ng-include="'app/views/menu.html'"></div>
<h2>Welcome Google SpreadSheet Page</h2>
<button class="btn btn-primary"
data-ng-click="read()" style="position: absolute;width: 199px;height: 35px;left: 0px;top: 190px;">View In GoogleSheets</button>
</div>
<iframe id='ifr' src='https://docs.google.com/spreadsheets/d/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/edit#gid=0'
style="position: absolute;width: 100%;height: 100%;left: 0px;top: 250px;" >
</iframe>
<iframe id='ifr' src='https://docs.google.com/spreadsheets/d/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/edit#gid=0'style="position: absolute;width: 100%;height: 100%;left: 0px;top: 250px;" >
</iframe>
这是我的 Js 代码,
$scope.read = function () {
var params = {
"range":"Sheet1!A1:B1",
"majorDimension": "ROWS",
"values": [
["Hello","World"]
],
}
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://sheets.googleapis.com/v4/spreadsheets/1sd4HEFMsK3WJyHgcs1crX-30LqkBum30kxdH0qCwL5Y/values/Sheet1!A1:B1?valueInputOption==USER_ENTERED;headers=false');
xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
xhr.send(JSON.stringify(params));
};
}]);
您有 valueInputOption==USER_ENTERED
而不是 valueInputOption=USER_ENTERED
。两个等号而不是一个。错误消息告诉您相同的信息:"Invalid value at 'value_input_option' (TYPE_ENUM), \"=USER_ENTERED\""
-- =USER_ENTERED
不是有效值,但 USER_ENTERED
是。