Wikimedia API Portal
  Home | Discuss | Fork this notebook on PAWS

Getting featured content from Wikipedia

Many Wikipedias include a daily featured article and other curated content on their homepages. You can see an example of this on English Wikipedia and Hebrew Wikipedia. The Wikimedia API lets you access this content programmatically, adding high-quality, multilingual content to your apps. In this tutorial, you'll use the API to extract information about today's featured article, featured image, and latest news.

Download this sample as a Jupyter Notebook/API-Portal/wikimedia-api-portal-featured-content.ipynb?format=raw)

The Wikimedia API supports featured content in over 12 languages based on the type of content. You can see language availability for each type of featured content by visiting the API Portal. While a Wikipedia may include featured content on its main page, not all Wikipedias are integrated into the Wikimedia API. Check the API changelog for the latest updates on language support.

API authentication: These examples use a User Agent header to identify the source of the request and an OAuth 2.0 access token for authentication. To learn about authentication for the Wikimedia API, visit the API Portal.

Today's featured article

Editors from across Wikipedias select and curate quality articles to feature on their wiki's homepage. The Wikimedia API featured content endpoint allows you to access the daily featured article in over 10 languages. To use this endpoint, you'll need today's date in YYYY-MM-DD format and the language code. Language codes are usually two or three letters, such as en for English, he for Hebrew, and fa for Persian. To get the language code for your language, review the list of supported languages on the API Portal.

Once you've made request, you can extract information about today's featured article (tfa) from the JSON response. In this example, we'll use the title of the article, the link to the original article on Wikipedia, a short extract, and a thumbnail of the article's lead image. For the complete list of properties returned by the API, read the docs.

Wikimedia Commons is a collection of over 60,000,000 freely usable media files, many of which are used in Wikipedia articles. The Wikimedia API featured content endpoint includes information about the daily featured image from Wikimedia Commons.

When featuring a free image, include information the attibutional: a link to x, y, and z. The Wikimedia API provides this information, you can you correctly attribute the work. The Wikimedia API currently supports featured image information in English only.

News

Some Wikipedias feature the latest news stories on their homepages, which we can also access using the featured content endpoint. Note that in-the-news content is only available for the current date. For example, to get the news stories featured on the main page of English Wikipedia:

As we did before, we can change the base URL to get today's news from another Wikipedia. For example, here's today's news from French Wikipedia. You can see that the featured stories aren't consistent between languages. This is because each Wikipedia is an independently managed community, and the stories featured depend on available articles and cultural context. You may also notice slight formatting differences between wikis.

You should now be able to use the Wikifeeds API to get featured content from Wikipedias.

To fork, edit, and re-run this Jupyter Notebook, download the source, and upload to PAWS using your Wikimedia account.

For more information about these endpoints, see the API reference.


This tutorial is licensed under the Creative Commons Attribution-ShareAlike License.