google-apis-explorer - Google 幻灯片批量更新错误 - “收到无效的 JSON 有效负载。未知名称”和“无法绑定查询参数”
问题描述
我正在尝试写入幻灯片元素。
我不断收到“收到无效的 JSON 有效负载。未知名称”和“无法绑定查询参数。字段”的错误响应
我的要求是
{
"requests": [
{
"deleteText": {
"objectId": "g33c4ea3b90_0_9",
"textRange": {
"type": "FROM_START_INDEX",
"startIndex": 0
}
}
},
{
"insertText": {
"objectId": "g33c4ea3b90_0_9",
"text": "$8.23",
"insertionIndex": 0
}
}
]
}
我在 PHP 中手动卷曲请求:
$params = '
{
"requests": [
{
"deleteText": {
"objectId": "'.$page_object_id.'",
"textRange": {
"type": "FROM_START_INDEX",
"startIndex": 0
}
}
},
{
"insertText": {
"objectId": "'.$page_object_id.'",
"text": "$8.23",
"insertionIndex": 0
}
}
]
}
';
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_CUSTOMREQUEST => 'POST' ,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false ,
CURLINFO_HEADER_OUT => true ,
CURLOPT_VERBOSE => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
$obj = json_decode($content, true);
print_r( $obj );
当我从API Explorer调用它时,它可以完美运行,但不能从我的服务器调用。
解决方案
所以问题是在请求参数json字符串中使用双引号而不是单引号。
所以以下工作:
{
'requests': [
{
'deleteText': {
'objectId': 'g33c4ea3b90_0_9',
'textRange': {
'type': 'FROM_START_INDEX',
'startIndex': 0
}
}
},
{
'insertText': {
'objectId': 'g33c4ea3b90_0_9',
'text': '$44.23',
'insertionIndex': 0
}
}
]
}
我已经为此工作了两天。
推荐阅读
- android - 如果我的 api 密钥有效且适当,但 android studio 仍然显示错误,请在颤振中传递有效的 api 密钥,解决方案是什么?
- react-native - 无法解决依赖“react-native-pure-chart@*”(网络请求失败)
- c++ - 创建一个 C++ 程序以查找给定整数数组中的整数对的数量,其总和等于指定数字
- uwp - 如何获取已安装的 nuget 包信息
- php - 为什么我的提交按钮不能将信息发送到我想要的电子邮件?(PHP)
- cordova - 应用程序和打开的窗口之间的通信
- php - 通过 PHP 生成 Excel 工作表 (CSV)
- typescript - 如何在新的命名空间下使用已经声明的类型?
- java - 在 Android 中使用 ContentProvider+Room 访问数据库的最佳实践是什么?
- netsuite - 如何在 NetSuite 中从 SOAP 请求中设置一个空的自定义国家/地区字段