Twitter API V2 回复推文(使用不记名令牌获取 403(不支持的身份验证))
得到这些错误
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": "",
"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 = ``;
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);
}
}
我正在努力寻找一种方法来使用 Twitter API V2 回复一条推文,但似乎没有终点可以做这样的事情,在 Twitter API V2 包中我找到了一条推文的方法,但我正在努力回复,你能帮我解决这个问题吗?谢谢。
回答如下: