Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't post tweet using Twitter free developer plan #485

Open
matteocoppola opened this issue Jun 17, 2023 · 13 comments
Open

Can't post tweet using Twitter free developer plan #485

matteocoppola opened this issue Jun 17, 2023 · 13 comments

Comments

@matteocoppola
Copy link

matteocoppola commented Jun 17, 2023

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?

@ChrisArchitect
Copy link

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

@ry0y4n
Copy link
Contributor

ry0y4n commented Jun 18, 2023

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)"}%           

@alkihis
Copy link
Collaborator

alkihis commented Jun 18, 2023

@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)

@ry0y4n
Copy link
Contributor

ry0y4n commented Jun 18, 2023

Wow! Thank you for your information!

v2.tweet() works successfully!

@matteocoppola
Copy link
Author

matteocoppola commented Jun 18, 2023

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?

@danjiro
Copy link

danjiro commented Jun 19, 2023

had to update implementation as well and can confirm updating to client.v2.tweet works using api key and secret (not oauth)
Screenshot 2023-06-19 at 1 07 56 pm

If you're attaching media: v2.tweet('message', { media: { media_ids: ['123'] } })

@matteocoppola
Copy link
Author

matteocoppola commented Jun 19, 2023

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.

@massanishi
Copy link

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.

@ChrisArchitect
Copy link

"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!

@hilmanski
Copy link

thanks! using v2 work for me

@arantespp
Copy link

arantespp commented Jul 6, 2023

In case it's useful for someone, my app only worked after changing this project "Project use" to "Making a Bot"

image

@hitwill
Copy link

hitwill commented Sep 28, 2023

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);
}
`

@mathix420
Copy link

In my case I had to wait for a couple of minutes before it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants