Hello, I’m trying to use the twitter api to tweet “test!!” my issue is that it’ll return with a 403 error. I’m unsure why this is happening.
My code:
const app = require('express')()
const TwitterApi = require("twitter-api-v2").default
let currentCodeVerifier = ""
const twitterClient = new TwitterApi({
clientId: "id",
clientSecret: "secret"
})
app.get("/callback", async(req, res) => {
twitterClient.loginWithOAuth2({
code: req.query.code,
codeVerifier: currentCodeVerifier,
redirectUri: "http://localhost:3000/callback"
})
.then(async ({client}) => {
await client.v2.tweet("test!!")
res.sendStatus(200)
})
.catch((e) => {
console.log(e)
res.send("invalid")
});
})
app.get('/redirect', (req, res) => {
const {url, codeVerifier} = twitterClient.generateOAuth2AuthLink("http://localhost:3000/callback", { scope: ['tweet.write'] })
currentCodeVerifier = codeVerifier
res.redirect(url)
})
app.listen(3000, () => {
console.log("LISTENING")
})
I assume that everything here is fine, but im unsure why this happens. It redirects to my callback and it seems to work fine, just doesn’t send a tweet.
my oauth2 settings:
thanks in advance!
someone plz help thx
its been 4 days and I still have this stupid error
403 Error is an Authentication Error.
You remembered to use an API Key, right?
If not, then you’ll need one in order to use the API.
1 Like
may I ask what you mean by API key? I thought all you needed was the ClientId and the ClientSecrect
Take a look at Step 2 of the Getting Started Guide 
where would I put those tokens in my request?
also sorry for the dumb questions, it’s my first time use oauth2 .