getting these error
Error Part
{
"title": "Unsupported Authentication",
"detail": "Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint. Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].",
"type": "https://api.twitter.com/2/problems/unsupported-authentication",
"status": 403
}
const { TwitterApi } = require("twitter-api-v2");
const config = require("../../config");
const client = new TwitterApi({
appKey: config.twitter_config.api_key,
appSecret: config.twitter_config.api_secret,
accessToken: config.twitter_config.access_token,
accessSecret: config.twitter_config.access_secret,
});
const bearer = new TwitterApi(process.env.BEARER_TOKEN);
const twitterClient = client.readWrite;
const twitterBearer = bearer.readOnly;
module.exports = { twitterClient, twitterBearer };
// i tried with these 2 methods
async function replyToTweet(tweetId, replyMessage,accesstoken) {
const accessToken =accesstoken ;
const url = `https://api.twitter.com/2/tweets`;
const headers = {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
};
const data = {
hidden: false,
in_reply_to_user_id: tweetId,
status: replyMessage,
};
try {
const response =await axios.post(url,{
tweet:{
in_reply_to_status_id:tweetId,
text:replyMessage,
}
},{headers});
console.log('Reply sent successfully:', response);
} catch (error) {
console.error('Error replying to tweet:', error);
}
}
async function replyToTweet() {
try {
const tweet = await client.v1.tweets.reply(tweetId, {
status: "maggi reply",
});
console.log('Reply sent successfully:', tweet.text);
} catch (error) {
console.error('Error replying to tweet:', error);
}
}
I am trying hard to find a way to reply to a tweet with Twitter API V2, but it seems there is no endpoint for doing something like that, in Twitter API V2 package i found a way to a tweet, but i am struggling with replies, can you please help me with this? Thanks.