I have a JavaScript code snippet designed for Zapier that allows for a ‘like’ action on a specific tweetId
. I’m attempting to adjust the code so that it executes a ‘retweet’ action instead. Below is the current code:
var consumerKey = 'YourConsumerKey';
var consumerSecret = 'YourConsumerSecret';
var accessToken = 'YourAccessToken';
var accessTokenSecret = 'YourTokenSecret';
function generateSignature(key, data) {
// Signature generation logic...
}
var tweetId = input.tweet_id;
// Generate unique nonce
function createNonce(length) {
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var nonce = '';
for (var i = 0; i < length; i++) {
nonce += characters.charAt(Math.floor(Math.random() * characters.length));
}
return nonce;
}
var nonce = createNonce(32);
var timestamp = Math.floor(Date.now() / 1000);
// Set up the API call for liking a tweet
var requestUrl = 'https://api.twitter.com/1.1/favorites/create.json?id=' + tweetId;
fetch(requestUrl, {
method: 'POST',
headers: {
'Authorization': 'OAuth oauth_consumer_key="' + consumerKey + '"...'
}
})
.then(response => response.json())
.then(result => callback(null, result))
.catch(error => callback(error));
I believed that changing the following line:
var requestUrl = 'https://api.twitter.com/1.1/favorites/create.json?id=' + tweetId;
to:
var requestUrl = 'https://api.twitter.com/1.1/statuses/' + tweetId + '.json';
based on Twitter’s documentation would do the trick, but it seems to be ineffective. Can someone point out where I might be going wrong?