Unable to Tweet using create_tweet()

Viewed 803

I've provided the key, secret key & tokens for my Twitter Dev account -

nclient = tweepy.Client(consumer_key=consumer_key, consumer_secret=consumer_sec_key,
                    access_token=auth.access_token, access_token_secret=auth.access_token_secret)

And then I tried Tweeting a new Tweet -

new_tweet = nclient.create_tweet("First tweet!")

It gives me the below error -

TypeError: create_tweet() takes 1 positional argument but 2 were given

When I try running the below command -

new_tweet = nclient.create_tweet(text = "First tweet!")

It gives me the below error -

Forbidden: 403 Forbidden

Please help me with a resolution for this issue.

2 Answers

The TypeError is because Client.create_tweet doesn't accept text as a positional argument. The 1 positional argument being referred to in the error is self.

Based on this comment, you're very likely using credentials that don't have the write permission. If you have already given your app the write permission, you need to regenerate your credentials afterwards and use those new credentials.

See the FAQ section on this in Tweepy's documentation.

If that's not the issue, then make sure you're not using a standalone app. Twitter API v2 requires that you use a Project.

I revoked the previous keys & tokens from the Twitter app and regenerated those. Then I used it in the below commands and now I'm able to tweet, delete the tweet and do other activities.

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
new_tweet = api.update_status(status = 'First tweet from #python !') #post a tweet
new_tweet.destroy() # delete a tweet

Thank you all for the help provided!

Related