How does an API work?

958 views

Twitter recently announced they will no longer support free access to the Twitter API. Everyone seems up in arms about it and I can’t figure out what an API even is. What would doing something like this actually affect?

I’ve tried looking up what an API is, but I can’t really wrap my head around it.

Edit: I’ve had so many responses to read through and there’s been a ton of helpful explanations! Much appreciated everyone 🙂 thanks for keeping this doofus in the know

In: 419

41 Answers

Anonymous 0 Comments

An API is a program that returns data. It gives people access to the data without using the website.

My wife uses it for research in college. She can request data from Twitter with specific dates and search terms, then with that data she can make a spreadsheet that shows thousands of tweets related to her study. So instead of using the Twitter website and copy and pasting a bunch of tweets, she can use the API to download thousands at once

Anonymous 0 Comments

APIs are used to communicate between systems (it’s the middleman between systems), where the API just exposes an interface that other developers can use. Developers that call the API don’t care how the API works, what it does or where/how it gets the data you want, all you care about is that you get what you wanted.

Imagine a restaurant; you come in, sit at a table and a waitress comes. You tell the waitress what you want to order, then the waitress brings you your meal.

Now, you don’t care how the meal was made, who cooked it, or from which ingredients, likewise you also don’t care what the waitress had to do in order to get and bring you your meal. All you care is that they brought you your meal and you didn’t have to do anything else other than tell the waitress what you wanted.

The waitress is the API in this case (the middleman between you and the kitchen), the kitchen is the server’s backend and the customer is the developer.

Anonymous 0 Comments

You are a baker. You bake variety of baked goods. You sometimes take orders from people – but those people arent bakers. They have no idea how to tell you to use specific mix of grain, or to add exact amount of oil. You also dont want to just let them into your kitchen and let them do what they please.

So you hire a youngster, and place him near your door. You give customers a list of words that they can give the youngster – such as “More puffy”, “No wheat”, “less crust” etc. Then the youngster will come to you in the kitchen and translate it to actual recipes – “person A needs more grain, person B wants the expensive flour, etc”.

API is a way for you to interact with a closed system. Its like a box with buttons, pressing a button sends (or receives) a specific piece of information to or from the closed system. You can press a button that says “Give me list of active users”, and box would print out a piece of paper with the list of users. You dont need to know how it stores this data, or how it accesses it, or how it prints it. You just need to know the correct phrase (“Give me list of active users”) to trigger the effect (prints out list of users).

Twitter restricting free access to API means that you now have to pay to be able to press these buttons.

Anonymous 0 Comments

An API is something that passes information or data from an app to another app. Think of this like you (the requesting app) asking for a hamburger and fries in a restaurant (the app sending the info). So you put an order and you get a hamburger and fries on your plate.

The inside workings in the kitchen – the ham being cooked, the potatoes being sliced and fried – are away from your knowledge and it doesn’t matter to you (assuming you trust the restaurant). The API is like the waiter who gets you what you requested. This way, the programs behind many apps request information and the API is the middleman between these two.

Usually apps use APIs to make their work easier. Like Uber doesn’t have to recreate Google maps to show the driver coming to you, they just use the Google maps API. At the same time, the entire Google maps program is not available to Uber, they only request what they need to show on their app and get it from Google maps.

Twitter not making their API available for free would mean analytics apps, management tools and other apps that use Twitter information will be affected.

Anonymous 0 Comments

To add on to other explanations and really emphasize why an API is useful:

Most websites/programs (let’s call them “apps” in general) are designed to be used by humans. As a human Twitter user, you can press buttons and type things in the app to follow people, search, and send your own tweets.

An API lets another computer program use the app, instead of a human. Of course, there are ways to imitate human input with a program, but they tend to be pretty inconvenient. With an API, you can conveniently write a computer program that uses Twitter, and do all the things a human would.

This is great if, for example, you need to do large Twitter searches to collect data (a human user would have to manually search and copy paste all the results—much easier to let the computer do it), or if you’re making a Twitter bot that collects news articles about a certain topic, or a customer service bot that responds to complaints from customers on your company’s Twitter, or any number of other uses.

Anonymous 0 Comments

An API, especially in the context an online service, is a way for code to interface with that service. For instance, you could write a python script that posts tweets automatically, and the bit of code that actually posts the tweet is accessing Twitter’s API. In python, you could use the ‘tweepy’ library for this, which is a bunch of code that people have written to make this process easier. But under the hood, what is happening is basically that the code generates a long URL and then submits this over the internet. You could write this entire URL by hand (well, keyboard…), but it’s easier to automate it. The URL contains information about the server that you want to send the request to (Twitter), as well as details of that request – for instance, the command to post a tweet, the contents of that tweet, the credentials for the account that the tweet should be posted to, and so on. If you copied this URL and posted it into a browser, the same thing would happen: your request would be submitted to the Twitter API, and a tweet would be posted (if the request was successfully processed).

In short, it allows you to automate ways to interact with a service such as Twitter. So instead of hiring someone to write tweets, you can just have a script running on your computer. Of course this only works for content that can be generated automatically (or which you have created beforehand to be posted later). Like, I could write some code that, once every minute, requests the current temperature in New York from a weather service’s API, and then posts a tweet saying “It is currently X°C in New York!” (where X is the temperature we got from the weather service).

Maybe from this example you can already start to see the problem: if individuals and companies massively start using an API, sending requests to it all the time, then it will take a lot of server capacity to process all those requests. And servers costs money. So, a service like Twitter may decide that it’s no longer worth it for them to give away access to their API for free, and start charging people for it.

Anonymous 0 Comments

You access twitter with the Twitter app, or through Twitter’s web page. They have provided you with a human-accessible interface to use their service.

Suppose you want to build a talking fish that every hour reads out the last tweet posted by your favorite celebrity. Your talking fish isn’t going to have a little guy inside, scrolling through the Twitter app, or the Twitter web page. Your talking fish needs some way of accessing Twitter that doesn’t require your fish to use the app, or a web page, or otherwise use fingers or eyes. It needs a way to access twitter programmatically.

Twitter doesn’t just provide a human interface to access its service. It also provides a means for your computer or other device to access the service directly. You can program the computer in your talking fish to access Twitter directly, download the latest tweet from your celebrity, and then convert it to speech and play it.

The interface Twitter provides for computers to access their service is the API.

The problem that Musk is (ostensibly) trying to solve is that the API doesn’t just allow bots to read twitter. It also allows them to post to twitter.

Anonymous 0 Comments

APIs allow people to build apps and websites that are able to communicate with Twitter. Say you want to upload a tweet from your PlayStation? An API (from Twitter) is what makes it possible to do that.

It’s common practice that a social media (and others) an API is free to use. It helps drive traffic and engagement up. So it’s a win win.

Anonymous 0 Comments

An API is Application programming interface. Application means it’s a program (in simple), programming that its purpose is to serve for other programs and interface that it allow communication between two different things.

an API is a program that allow other program to communicate with them. In the most common use, it allows any other program you make to call said API, over the internet, and ask for information.

In the case of twitter, to give an example of what it could be: the Api has a function get_last_tweet_from_user(user). Whenever someone call that function they call twitter_api.get_last_tweet_from_user(ArtAndGals) and the api sends back the last tweet from ArtsAndGals. Your program can then do whatever it wants with the information received.

It is of course very simplified, as there are securities, from password to prevent anyone from accessing, to load balancer to ensure someone isn’t sending 10 billions request a second to crash the servers, but that’s the basic principle.

Now, while I do not know what twitter changed nor why the outrage is happening, I can make a few educated guess. The classic issue is that if something that already exist is modified, every single application that used it need to update. For example, our old get_last_tweet_from_user(user) could have been replaced with a new, more global function of get_last_tweet_from(type, value). Type could be user, in which case it works the same way as before, but it could also be tag. The same function now serve to get from either a tag, or a user. While having more option is great, it’s still extra work for everyone involved.

The other possible issue is that they now require stricter security procedure, or even worse, expensive access. No longer can you just call the API for information, you have to also use an account and potentially pay to access it.

Hopefully it helps you understand what an API is and how it works, and maybe to see why it cause trouble to change an API like that.

Anonymous 0 Comments

APIs are how third-party apps communicate with the system. The legal significance of this change is that any service that is getting data from Twitter will now have to pay for it. This generally means free apps will have to start charging their users.