Giter Club home page Giter Club logo

Comments (3)

geduldig avatar geduldig commented on June 2, 2024 1

The following code worked for me.

from TwitterAPI import TwitterAPI, TwitterRequestError, TwitterConnectionError

try:
        api = TwitterAPI(
                consumer_key, consumer_secret, access_token_key, access_token_secret,
                auth_type='oAuth1',
                api_version='2')

        r = api.request('tweets', {'text':'a test to test'}, method_override='POST')

        for item in r:
                print(item)

except TwitterRequestError as e:
        print(e.status_code)
        for msg in iter(e):
                print(msg)

except TwitterConnectionError as e:
        print(e)

except Exception as e:
        print(e)

from twitterapi.

cboden avatar cboden commented on June 2, 2024 1

Thanks for getting back to me so quickly @geduldig. Your code is correct, the problem was on the Twitter side of things. I'll leave steps below in case anyone else comes across this:

  • App stopped working after a few years. I was using v1 of the Twitter API, which they stopped supporting. I was using a standalone Twitter app. Apps are now required to be part of a Project.
  • There is an option to attach existing Apps to a Project, try that. If that doesn't work (Twitter threw errors) then you need to delete your existing App and create a new one under your Project
  • In the new App setup permissions under "User authentication settings". Make sure to select "Read and write" under App permissions. This will generate OAuth2 tokens so your app can be used on other user's behalf. Even though this isn't what I'm using the app for, this step is required.
  • Under the App's "Keys and Tokens" (re)generate new API Key and Secret pairs and Access Token and Secret pairs. If these existed before the previous step, they must be regenerated.

from twitterapi.

cboden avatar cboden commented on June 2, 2024

I also attempted this code and received the following error:

TwitterAPI(
  oauth2_access_token=os.getenv("TWITTER_BEARER_TOKEN"),
  auth_type="oAuth2User",
  api_version="2",
)
api.request("tweets", {"text": "Hello World"}, method_override="POST")

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].

from twitterapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.