这是我的代码
function sendScheduledSMS() {
const apiKey = [telzio_api]
const token = [my_token]
const number_id = [number_id]
const recipient = [recipient_number]
const text = 'test';
const url = 'https://api.telzio.com/v3/conversations/sms/create-conversation';
const payload = {
'number_id': number_id,
'recipient': recipient,
'text': text
};
const options = {
'method': 'post',
'contentType':'application/x-www-form-urlencoded',
'payload': JSON.stringify(payload),
'headers': {
'Authorization': 'Bearer ' + token
}
};
try {
const response = UrlFetchApp.fetch(url, options);
const result = JSON.parse(response.getContentText());
Logger.log('SMS sent successfully: ' + result);
} catch (error) {
Logger.log('Error sending SMS: ' + error);
}
}
当通过 Google Appscript 执行时,我不断收到 403 响应,但是当我通过 Postman 调用它时,我可以获得 200 响应。我不再知道我的代码是否有问题,或者我需要在 Appscript 中执行其他步骤才能让我调用 API。请帮忙。谢谢你。
作为 Telzio v3 文档的参考 https://api.telzio.com/v3/index.html#tag/Conversations/paths/~1v3~1conversations~1sms~1create-conversation/post
当我看到你提供的官方文档时,似乎“内容类型”是
application/json
。那么,下面的修改怎么样?
const options = {
'method': 'post',
'contentType': 'application/x-www-form-urlencoded',
'payload': JSON.stringify(payload),
'headers': {
'Authorization': 'Bearer ' + token
}
};
const options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload),
'headers': {
'Authorization': 'Bearer ' + token
}
};