Ela*_*zzi 5 google-sheets google-apps-script
我正在尝试使用 Google Apps 脚本发送 POST 请求。\n根据文档,该请求由三部分组成:
\n但UrlFetchApp.fetch只允许2个参数。
我尝试以完全不同的方式实现它。
\n目前,我的代码如下所示:
\nfunction qwe(){\n \nconst url = 'https://api-seller.ozon.ru/v1/product/info/prices';\nconst data = {\n "page": 1,\n "page_size": 100};\n\nconst response = UrlFetchApp.fetch(url, { \n body: JSON.stringify(data), // \xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5 \xd0\xbc\xd0\xbe\xd0\xb3\xd1\x83\xd1\x82 \xd0\xb1\xd1\x8b\xd1\x82\xd1\x8c '\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xbe\xd0\xb9' \xd0\xb8\xd0\xbb\xd0\xb8 {\xd0\xbe\xd0\xb1\xd1\x8a\xd0\xb5\xd0\xba\xd1\x82\xd0\xbe\xd0\xbc}!\n headers: {\n "Host": "api-seller.ozon.ru", \n "Client-Id": "28000",\n "Api-Key": "65db5b96-cbb6-4b68-8f33-c8c000000000000",\n "Content-Type": "application/json"\n }\n });\n const json = response.json();\n console.log('Done:', JSON.stringify(json));\n}\nRun Code Online (Sandbox Code Playgroud)\n我收到错误"Exception: request failed for https://api-seller.ozon.ru returned code 405"\n请告诉我如何做到这一点?
谢谢田池!!
\n代码的工作版本:
\nfunction qwe(){\n \n const url = 'https://api-seller.ozon.ru/v1/product/info/prices';\n const formData = {\n "page": 1,\n "page_size": 100};\n\n const headers = { \n "Client-Id": "28100",\n "Api-Key": "65db5b96-cbb6-4b68-8f33-c8c000000000"\n };\n Logger.log(JSON.stringify(formData));\n\n const options = { \n 'method' : 'post',\n 'contentType': 'application/json',\n 'headers': headers,\n 'payload': JSON.stringify(formData)\n };\n\n const response = UrlFetchApp.fetch(url, options);\n //Logger.log(response);\n var data = JSON.parse(response);\n Logger.log(data);\n //const json = response.json();\n //console.log('\xd0\xa3\xd1\x81\xd0\xbf\xd0\xb5\xd1\x85:', JSON.stringify(json));\n}\nRun Code Online (Sandbox Code Playgroud)\n
can*_*ane -1
如果您使用的是https方案,请再检查一次。
const baseUrl = 'https://api-seller.ozon.ru/';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6425 次 |
| 最近记录: |