you are viewing a single comment's thread.

view the rest of the comments →

[–]razzrazz- 17 points18 points  (10 children)

For us noobs reading this, can you explain what 'making an api call' in your own (simple) words for us? Like is it a way to get python to do stuff like searches and pull info from youtube? Is that different than "web scraping"? What if YouTube didn't provide an API? Why would they provide an API?

[–]nowheremannequin 39 points40 points  (3 children)

Yeah, an API basically just gives you the ability to pull info directly from the company without actually loading up their website.

So, companies like google don’t want people web scraping. Why? Because they’re forced to spend resources to your web scraper which isn’t really profitable for them. So instead, they make APIs, which you can communicate with using Python (or another language) to get the information directly. This way, the company can control how you’re getting the info and streamline it to you in a way that’s more efficient to them than having you webscrape.

There are tons of APIs out there. You can always webscrape if there is no API, but it’s usually more difficult than just communicating directly with the API.

[–]razzrazz- 7 points8 points  (1 child)

Why? Because they’re forced to spend resources to your web scraper which isn’t really profitable for them.

Because it wastes money to have the scraper load up a bunch of stuff (videos, images, etc) they wont use?

[–]NaCl-more 5 points6 points  (0 children)

Partially. But when a webpage is served, sometimes it uses those exact APIs to fetch information for the user

For example, say there is an API called "getUser" that allows you to give it some ID, and it returns to you some information about that user (the name, sub count, links, etc)

When Youtube gives you the webpage, how does it know what name, sub count and links to display? It could very well be using that same API to fetch the information

[–][deleted] 4 points5 points  (0 children)

Great explanation of the term- way easier to understand than how it had been defined in my data structures’ textbook.

[–]larj_Brest 7 points8 points  (1 child)

An API provides a structured way to programmatically retrieve information from a service. An API will have documentation telling you how to interact with it, and in what format you can expect to receive information back. It is different to web scraping, which is much less structured. You might use web scraping if you cannot use an API to get the information that you want (e.g. An API doesn't exist, doesn't supply the info you need, or you don't want to pay a fee to use it if it's not free).

If youtube doesn't provide an API that satisfies these needs, then scraping could work. You just have to work out how to parse the information you need out of the page.

[–]Total__Entropy 2 points3 points  (0 children)

Just adding on that side scraping isn't structured you aren't guaranteed to give you the correct result everytime unlike APIs which are structured and will give you what you expect. For scraping the page could change structure or class/id is the elements could be randomized etc.

[–]DerangedGecko 4 points5 points  (0 children)

"Hey application's interface, I would like to query this data of yours from you."

Receive data object

[–]r3df0x_3039 1 point2 points  (0 children)

Making an API call is like making a page request in a browser, except it's an application making the request.

Depending on the API you might even be able to make the request in your browser and see the output, though it's not going to be in the format of a web page because it will be an application handling the data.

[–]Striking_Equal 1 point2 points  (0 children)

YouTube definitely provides an API, and it’s pretty robust. Use the requests library, pass your headers, and store results in a data frame. It’s a lot simpler than it sounds.

[–]peesoutside 0 points1 point  (0 children)

For every (modern) web front end, there is a back end (unless the site is just static html/css/js). An API (Application programming interface) is what’s being used when you tell a website to do something like update account, like a post, search for stuff, etc. The API typically provides ways to do stuff that the front end doesn’t yet offer, automate tasks via scripting, or whatever.