Skip to content

matuqam/Twitter-API-v2-sample-code

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter API v2 sample code v2

Sample code for the Twitter API v2 endpoints. Individual API features have folders where you can find examples of usage in several coding languages (Java, Node.js, Python, R, and Ruby).

Prerequisites

Using the code samples

In order to run the samples in this repository you will need to set up some environment variables. You can find your credentials and bearer token in the App inside of your Project in the dashboard of the developer portal.

For OAuth 1.0a samples, you will need to export your api_key and api_secret_key in your terminal. Be sure to replace <your_api_key> and <your_api_secret_key> with your own credentials without the < >.

export API_KEY='<your_api_key>'
export API_SECRET_KEY='<your_api_secret_key>'

For samples which use bearer token authentication, you will need to export the bearer token. Be sure to replace <your_bearer_token> with your own bearer token without the < >.

export BEARER_TOKEN='<your_bearer_token>'

programming language requirements

Python environment set up

You will need to have Python 3 installed to run this code. The Python samples use requests==2.24.0 which uses requests-oauthlib==1.3.0.

(Optionally) It is common and recommended not to install required package globally, but locally under project subfolder using venv:

python3 -m venv venv
source venv/bin/activate

You can install these packages as follows:

pip install -r requirements

Additional resources

We maintain a Postman Collection which you can use for exercising individual API endpoints.

Support

  • For general questions related to the API and features, please use the v2 section of our developer community forums.

  • If there's an bug or issue with the sample code itself, please create a new issue here on GitHub.

Contributing

We welcome pull requests that add meaningful additions to these code samples, particularly for languages that are not yet represented here.

We feel that a welcoming community is important and we ask that you follow Twitter's Open Source Code of Conduct in all interactions with the community.

License

Copyright 2021 Twitter, Inc.

Licensed under the Apache License, Version 2.0: https://www.apache.org/licenses/LICENSE-2.0

house cleaning (remove non python enpoint files)

E='\.java'; for I in $(tree -P *$E -f -i | grep -e "$E"); do rm $I; done
E='\.r'; for I in $(tree -P *$E -f -i | grep -e "$E"); do rm $I; done
E='\.rb'; for I in $(tree -P *$E -f -i | grep -e "$E"); do rm $I; done
E='\.js'; for I in $(tree -P *$E -f -i | grep -e "$E"); do rm $I; done

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%