In my day job, when I'm not learning things by reading and sharing here on DEV, I'm a developer advocate at Twitter. I've been doing this for quite a long time now, and I recognise that while I'm always learning for myself, I don't always stop to think about how other people learn.
I know that personally, I learn best from getting started guides, example code that makes sense, and the ability to "play with" an API using some kind of explorer or command line. I do not usually get so much from videos (but I love to take part in making them!).
How do YOU learn to use new APIs?
The more specific question / broader background...
In November, we launched Twitter API v2, which is a whole new way to access Twitter data, based on the OpenAPI specification, and with a more modern experience than v1.1 (which is around 11 years old - pretty rare for an API to last that long without major changes). We've hosted some Twitch streams and Twitter Spaces to talk about it.
We have documentation, a Postman Collection, and sample code.
xdevplatform
/
samples
Sample code for the X API v2 endpoints
X API v2 Sample Code
Working code samples for the X API v2 in Python, JavaScript, Ruby, Java, and R.
π Repository Structure
βββ python/ # 65 Python examples
βββ javascript/ # 59 JavaScript examples
βββ ruby/ # 58 Ruby examples
βββ java/ # 19 Java examples
βββ r/ # 5 R examples
βββ llms.txt # LLM-friendly documentation
βββ api-index.json # Machine-readable endpoint catalog
π Quick Start
1. Get API Credentials
Sign up at the X Developer Portal.
2. Set Environment Variables
For read-only operations (search, lookup):
export BEARER_TOKEN='your_bearer_token'
For user actions (post, like, repost, bookmark, etc.):
export CLIENT_ID='your_client_id'
export CLIENT_SECRET='your_client_secret'
For OAuth 1.0a (legacy endpoints):
export CONSUMER_KEY='your_consumer_key'
export CONSUMER_SECRET='your_consumer_secret'
3. Run an Example
# Python
cd python && pip install -r requirements.txt
python posts/search_recent.py
# JavaScript
cd javascript
node posts/search_recent.js
# Ruby
cdβ¦If you had the chance to request an educational resource about the Twitter API, what would you ask for? Tutorials, videos, Twitch, code? Any particular topic you want to know more about? Should we provide code in different languages - which ones, and why? Let me know in the discussion below, or follow me on Twitter and Tweet me a suggestion!
Top comments (16)
Twitter API's documentation is pretty straightforward and elaborative. In the start it was slightly complicated to understand but after knowing how the API works it was easy to follow. I learnt to use v1.1 and v2 endpoints from Twitter docs only :)
That's good to know, thank you! Did you use any existing code libraries to work with the v2 API, or did you build directly against the API endpoints for yourself?
Yes, I'm using a third-party node library to simplify making calls. This for v2 npmjs.com/package/twitter-api-v2 and Twitjs for v1 endpoints.
I read somewhere that your team is also working on first party libraries, that would be awesome! Also are there plans for Twitter Text npmjs.com/package/twitter-text but for v2 endpoints? I'm currently working on same and planning to open-source, just want to know if you guys are also working on it.
We've certainly been thinking about building some libraries. The challenge is identifying which languages are most commonly used (I note that you're using JS). Definitely keep an eye on our news here. The community has created some really good libraries as well, as you have discovered.
For twitter-text, there should be no need for a different version - it is a text tokenizer, and the format of the text contents of Tweets themselves have not changed between v1.1 and v2, so the same logic will work. Let us know via the GitHub issues on that repo if there are specific questions about it (that comes from Twitter Engineering internally, rather than from our DevRel team, but we work together on things like this)
Got it, thanks!
I really like flow diagrams. Show me what I'll need to do to get a specific thing working and I'm much happier.
Interesting, yes! I wonder if the new Mermaid support on GitHub Markdown will see more of these being used.
The official documentation works for me.
A game to apply and use your API services like Twilio quest. Quickstart tutorials that includes both video and example is good.
Nice to hear that you've enjoyed things like Twilio Quest π‘ I think Salesforce have done things along those lines before as well. It can be nice to have a sense of accomplishment as you progress through getting familiar with an API, I get that for sure. Thanks!
I think there are probably ways to enhance the Postman resources to go in this kind of direction, as well. I'll think about that.
Docs, a getting started guide with examples, API reference ... that's it really.
Do you often build directly on top of the βrawβ (JSON+HTTP) API, or look for and use a library?
If there's a library available for my target programming language, then yeah I'd probably use that library rather than going "low level" (REST/HTTP/JSON).
I love twitter API because using it I automate my tweets for 5am morning and my friends think that I am so punctual ππ and I use tweepy python library which makes it even easier.
With a good documentation is enough. But if you have the option to test all the functions in a sandbox is superb.