curl 僵尸程序API发布JSON谷歌表单脚本

8zzbczxx  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(131)

我有谷歌工作表的数据,我需要使用WhatsApp发送,所以我有Botmaker的API。他们给予了一个cURL和JSON数据,但我不知道如何使用cURL和JSON做后使用谷歌脚本功能。
这是cURL:

curl
- X POST
  --header 'Content-Type: multipart/form-data' 
  --header 'Accept: application/json' 
  --header 'access-token: myAccessToken'
-F chatPlatform=whatsapp
-F chatChannelNumber=############
-F platformContactId=############
-F mediaType=document

这是API的请求URL:“请访问以下网址:”
这是响应正文:无内容
这是响应代码:401
回应信头:

{
  "accept": "[application/json, application/xml, text/plain]",
  "access-control-allow-credentials": "true",
  "access-control-allow-headers": "bearer-token,access-token,Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin",
  "access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS, HEAD",
  "access-control-allow-origin": "https://go.botmaker.com",
  "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
  "cache-control": "must-revalidate,no-cache,no-store",
  "content-length": "0",
  "content-security-policy": "default-src 'self'",
  "date": "Sat, 11 Jun 2022 22:52:02 GMT",
  "permissions-policy": "geolocation=(self \"https://go.botmaker.com\"), microphone=()",
  "reason-phrase": "Cannot authenticate user with received tokens after applying [access-token] and accessToken [null]",
  "referrer-policy": "no-referrer",
  "server": "Botmaker",
  "strict-transport-security": "max-age=31536000; includeSubDomains",
  "via": "1.1 google",
  "x-content-type-options": "nosniff",
  "x-frame-options": "DENY"
}

我知道我需要使用UrlFetchApp.fetch
有人可以帮我创造

8ulbf1ek

8ulbf1ek1#

我找到了方法,下面是它对我的作用:

var userNumber = '123456789012' // to: cellular phone number 

const waNumber = '123456789012'; // from: cellular phone 
const accessToken = 'faketoken'; // use you token

// send a template
var url = 'https://go.botmaker.com/api/v1.0/intent/v2';

var headers = {
    'Content-Type': 'application/json' ,
    'Accept': 'application/json' ,
    'access-token': accessToken
};

var dataJson = { 
    "chatPlatform": "whatsapp",
    "chatChannelNumber": waNumber,
    "platformContactId": userNumber,
    "ruleNameOrId": "template_name" // the name of the template
};

var payload = JSON.stringify(dataJson);

var options = {
    'method': 'POST',
    'headers': headers,
    'payload': payload
};

var response = UrlFetchApp.fetch(url, options);
Logger.log(response);

相关问题