node-twitter-api-v2
node-twitter-api-v2 copied to clipboard
Can't post tweet using Twitter free developer plan
Describe the bug I'm following the library docs to authorize and post a tweet but it doesn't work with client.v1.tweet(). I've tried changing it to client.v2.tweet() but Twitter returns: "Authenticating with Unknown is forbidden for this endpoint. Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context]".
To Reproduce Here's the code snippet I'm using:
const client = new TwitterApi({
appKey: my_consumerKey,
appSecret: my_consumerSecret,
accessToken: my_accessToken,
accessSecret: my_accessTokenSecret,
});
const response = await client.v2.tweet('My tweet text for testing!');
Expected behavior Using the correct credentials the library should allow us to post a tweet correctly.
Is it even possible to use the library to tweet using the free developer plan?
the library works fine with free plan.
Just an idea, Check in your developer platform dashboard under User Authentication Settings that you have enabled "read/write" access under oauth 1.0 settings...... so that your keys are allowed to tweet
Same here !
My code, which I run every few days, stopped working after 2023/6/13. My environment is here.
- Node: 18.10.0
- twitter-api-v2: 1.15.0
- Twitter Developer Portal
- App permissions: Read and write
- Type of App: Web App, Automated App or Bot
Here is a part of my code.
const client = new TwitterApi({
appKey: secrets["appKey"],
appSecret: secrets["appSecret"],
accessToken: secrets["accessToken"],
accessSecret: secrets["accessSecret"]
});
const mediaIds = await client.v1.uploadMedia(`${__dirname}/video/ouput.png`);
console.log(mediaIds) # output some number
await client.v1.tweet(`${title} ${convertedUrl} @YouTubeより`, { media_ids: [mediaIds] });
and I got a error when v1.tweet
U{"error":"Error: Request failed with code 403 - You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product (Twitter code 453)"}%
@ry0y4n I think v1 API endpoints available in v2 API have been removed from free plan.
Use v2.tweet
instead to send a tweet. (but keep v1.uploadMedia
, as no replacement in v2 exists)
Wow! Thank you for your information!
v2.tweet()
works successfully!
the library works fine with free plan.
Just an idea, Check in your developer platform dashboard under User Authentication Settings that you have enabled "read/write" access under oauth 1.0 settings...... so that your keys are allowed to tweet
I've regenerated all the 4 keys/secrets and in the section "Access Token and Secret" there's the message "Created with Read and Write permissions"
Still, using the code at the original post doesn't work, returning 403 with this error: Authenticating with Unknown is forbidden for this endpoint. Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].
What am I missing? Surely something as @ry0y4a was able to use the v2.tweet() function.
As additional context I'm using Node 14 with this library. Maybe the version for 14 differs greatly from the version for Node 18? Even if in package.json the version is 1.15.0 something could be different?
had to update implementation as well and can confirm updating to client.v2.tweet
works using api key and secret (not oauth)
If you're attaching media: v2.tweet('message', { media: { media_ids: ['123'] } })
After several tests, I discovered that the secret wasn't being passed correctly to my function.
The library works well! We can close this issue.
I was using v2 tweet since last month, but it stopped working sometime this week with the 403 error.
My issue was I had to include the App, which was standalone, inside the Project in the developer portal. All these Twitter restructuring jargons, sigh.
"Authenticating with Unknown...."
It was in the error message all along, should have started there with debug before jumping to "the entire library is faulty".
Lessons for next time!
thanks! using v2 work for me
In case it's useful for someone, my app only worked after changing this project "Project use" to "Making a Bot"
the library works fine with free plan. Just an idea, Check in your developer platform dashboard under User Authentication Settings that you have enabled "read/write" access under oauth 1.0 settings...... so that your keys are allowed to tweet
I've regenerated all the 4 keys/secrets and in the section "Access Token and Secret" there's the message "Created with Read and Write permissions"
Still, using the code at the original post doesn't work, returning 403 with this error: Authenticating with Unknown is forbidden for this endpoint. Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].
What am I missing? Surely something as @ry0y4a was able to use the v2.tweet() function.
As additional context I'm using Node 14 with this library. Maybe the version for 14 differs greatly from the version for Node 18? Even if in package.json the version is 1.15.0 something could be different?
After enabling read/write - regenerating the tokens worked
This needs to be in the documentation
import Twitter from 'twitter-api-v2';
const client = new Twitter({
appKey: process.env.TWITTER_API_KEY,
appSecret: process.env.TWITTER_API_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_ACCESS_SECRET,
});
export function tweet(tweet: string) {
client.v2.tweet(tweet);
}
`
In my case I had to wait for a couple of minutes before it worked.