Hello, I am trying to code on google app script a program which allows to send a private message.
I can tweet but I can’t send a private message and twitter is giving me a 415 error.
But I find it strange because I can use the API to tweet.
Thank you in advance.
function run() {
var service = getService();
if (service.hasAccess()) {
var url = 'https://api.twitter.com/1.1/direct_messages/events/new.json';
var payload = {
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "********************",
},
"message_data": {
"text": "Hello world!",
}
}
}
};
var response = service.fetch(url, {
method: 'post',
payload: payload,
ContentType : "application/json"
});
var result = JSON.parse(response.getContentText());
Logger.log(JSON.stringify(result, null, 2));
} else {
var authorizationUrl = service.authorize();
Logger.log('Open the following URL and re-run the script: %s',
authorizationUrl);
}
}
Here is the error indicated.
system
Closed
#2
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.