Thanks for replying.
I have made a webhook which takes a post req and also takes a get req and returns the hmac as in helpers/security.js.
I am making a post req like
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
require('dotenv').config();
fetch('https://api.twitter.com/1.1/account_activity/webhooks.json?url=https://tw.up.railway.app/webhook/twitter', {
method: 'POST',
headers: {
'Authorization': `OAuth oauth_consumer_key=${process.env.API_KEY}, oauth_nonce="GENERATED", oauth_signature="GENERATED", oauth_signature_method="HMAC-SHA1", oauth_timestamp="GENERATED", oauth_token=${process.env.ACCESS_TOKEN}, oauth_version="1.0"`
}
})
.then(res => {
try {
return res.json();
} catch (e) {
return res.text();
}
})
.then(json => console.log(json))
What should I put in oauth_nonce, oauth_signature, and oauth_timestamp ?
When I make the req, I get error like
{ errors: [ { code: 215, message: 'Bad Authentication data.' } ] }
So this didn’t work…
Then tried Autohook
const { Autohook } = require('twitter-autohook');
require('dotenv').config();
(async ƛ => {
const webhook = new Autohook({
token: process.env.ACCESS_TOKEN,
token_secret: process.env.ACCESS_TOKEN_SECRET,
consumer_key: process.env.API_KEY,
consumer_secret: process.env.API_KEY_SECRET,
// ngrok_secret: 'value', // optional
env: 'env',
port: 1337
});
// Removes existing webhooks
await webhook.removeWebhooks();
// Listens to incoming activity
webhook.on('event', event => console.log('Something happened:', event));
// Starts a server and adds a new webhook
await webhook.start();
// Subscribes to a user's activity
await webhook.subscribe({oauth_token: process.env.ACCESS_TOKEN, oauth_token_secret: process.env.ACCESS_TOKEN_SECRET });
})();
This throws error
throw new AuthenticationError(response);
^
AuthenticationError: Forbidden. (HTTP status: 403, Twitter code: 200)
at tryError (d:\new-stuff\Tweet designer\node_modules\twitter-autohook\errors\index.js:53:12)
at Autohook.getWebhooks (d:\new-stuff\Tweet designer\node_modules\twitter-autohook\index.js:242:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Autohook.removeWebhooks (d:\new-stuff\Tweet designer\node_modules\twitter-autohook\index.js:261:22) at async d:\new-stuff\Tweet designer\autohookt.js:16:3 {
code: 200
}
Am I doing anything wrong in both cases ?
My project has Elevated access