|
1 |
| -# Twitter API v2 sample code [](https://developer.twitter.com/en/docs/twitter-api) |
2 | 1 |
|
3 |
| -Sample code for the Twitter API v2 endpoints. |
4 |
| -Individual API features have folders where you can find examples of usage in several coding languages (Java, Node.js, Python, R, and Ruby). |
5 |
| - |
6 |
| -* [Twitter API Documentation](https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api) |
7 |
| - |
8 |
| -## Prerequisites |
9 |
| - |
10 |
| -* Twitter API Essential Access ([sign up here](https://developer.twitter.com/en/portal/petition/essential/basic-info)) |
11 |
| -* A Project and an App created [in the dashboard](https://developer.twitter.com/en/portal/dashboard) |
12 |
| - |
13 |
| -## Using the code samples |
14 |
| - |
15 |
| -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](https://developer.twitter.com/en/portal/projects-and-apps). |
16 |
| - |
17 |
| -For OAuth 1.0a samples, you will need to export your consumer key and secret in your terminal. Be sure to replace `<your_consumer_key>` and `<your_consumer_secret>` with your own credentials without the `< >`. |
18 |
| - |
19 |
| -```bash |
20 |
| -export CONSUMER_KEY='<your_consumer_key>' |
21 |
| -export CONSUMER_SECRET='<your_consumer_secret>' |
22 |
| -``` |
23 |
| - |
24 |
| -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 `< >`. |
25 |
| - |
26 |
| -```bash |
27 |
| -export BEARER_TOKEN='<your_bearer_token>' |
28 |
| -``` |
29 |
| - |
30 |
| -## Language-specific requirements |
31 |
| - |
32 |
| -### Java environment set up |
33 |
| - |
34 |
| -If you use Homebrew, you can install a Java runtime using: |
35 |
| - |
36 |
| -```bash |
37 |
| -brew cask install java |
38 |
| -``` |
39 |
| - |
40 |
| -You will also need to download the relevant JAR files referenced in the individual samples in order to build and run the code. If you use an IDE, it may be able to do this automatically for you. |
41 |
| - |
42 |
| -### JavaScript (Node.js) environment set up |
43 |
| - |
44 |
| -You will need to have Node.js installed to run this code. All Node.js examples use `needle` as the HTTP client, which needs to be npm installed. For OAuth with user context requests, you'll need to install the `got` and `oauth-1.0a` packages. |
45 |
| - |
46 |
| -```bash |
47 |
| -npm install needle |
48 |
| -npm install got |
49 |
| -npm install oauth-1.0a |
50 |
| -``` |
51 |
| - |
52 |
| -### Python environment set up |
53 |
| - |
54 |
| -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`. |
55 |
| - |
56 |
| -You can install these packages as follows: |
57 |
| - |
58 |
| -```bash |
59 |
| -pip install requests |
60 |
| -pip install requests-oauthlib |
61 |
| -``` |
62 |
| - |
63 |
| -### Ruby environment set up |
64 |
| - |
65 |
| -You will need to have Ruby (recommended: >= 2.0.0) installed in order to run the code. The Ruby examples use `typhoeus` as the HTTP client, which needs to be gem installed. For OAuth with user context requests, you'll also need to install the `oauth` gem (see below). |
66 |
| - |
67 |
| -```bash |
68 |
| -gem install typhoeus |
69 |
| -gem install oauth |
70 |
| -``` |
71 |
| - |
72 |
| -## Additional resources |
73 |
| - |
74 |
| -We maintain a [Postman](https://getpostman.com) Collection which you can use for exercising individual API endpoints. |
75 |
| - |
76 |
| -* [Using Postman with the Twitter API](https://developer.twitter.com/en/docs/tutorials/postman-getting-started) |
77 |
| -* [Twitter API v2 on the Postman website](https://t.co/twitter-api-postman) |
78 |
| - |
79 |
| -## Support |
80 |
| - |
81 |
| -* For general questions related to the API and features, please use the v2 section of our [developer community forums](https://twittercommunity.com/c/twitter-api/twitter-api-v2/65). |
82 |
| - |
83 |
| -* If there's an bug or issue with the sample code itself, please create a [new issue](https://github.com/twitterdev/Twitter-API-v2-sample-code/issues) here on GitHub. |
84 |
| - |
85 |
| -## Contributing |
86 |
| - |
87 |
| -We welcome pull requests that add meaningful additions to these code samples, particularly for languages that are not yet represented here. |
88 |
| - |
89 |
| -We feel that a welcoming community is important and we ask that you follow Twitter's [Open Source Code of Conduct](https://github.com/twitter/.github/blob/main/code-of-conduct.md) in all interactions with the community. |
90 |
| - |
91 |
| -## License |
92 |
| - |
93 |
| -Copyright 2021 Twitter, Inc. |
94 |
| - |
95 |
| -Licensed under the Apache License, Version 2.0: https://www.apache.org/licenses/LICENSE-2.0 |
0 commit comments