1

我们可以使用 Google App Script 做这样的事情吗?-> 使用 REST API 将订单推送到 magento 2,订单将由 Google Sheet 获取。-> 当我尝试这样做时

<head>
<meta name="robots" content="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=5074a744e2e3d891814e9a2dace20bd4,719d34d31c8e3a6e6fffd425f7e032f3">
</script>
<body>
</body></html>

虽然当我使用身份验证 API 时它运行良好并返回令牌,但我在下一个 GET 请求中使用令牌(测试我使用 REST API 进行产品获取)。看起来 Magento 正在将 Google App Script 视为机器人。

这是我的代码。

function myFunction() {

var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();

var url1 = "https://www.traditionalfood...";

var options1 = {
'headers': { 'Content-Type': "application/json", 'Accept':"application/json"},
'method': "post",
'payload' : JSON.stringify({"username": "*****", "password":"********"})
};
var response1 = UrlFetchApp.fetch(url1, options1);

var json1 = response1.getContentText();
Logger.log("###################"+json1.replace(/\"+/g,"")); /// this request is fine, returning the token

var url2 = "http://www.traditionalfoods... Cedar Gum";

var options2 = {
'headers': {
'Content-Type': "application/json",
'Accept': "application/json",
'Authorization': "Bearer "+json1.replace(/\"+/g,""),
'method': "get"
}
};

var response2 = UrlFetchApp.fetch(url2, options2);

var json2 = response2.getContentText(); /// Here it is giving the response above mentioned.
Logger.log("###################"+json2);

}
4

0 回答 0