Code Monkey home page Code Monkey logo

bbc-news-api's Introduction

Logo

BBC News API

Discover the world of news through the lens of the BBC News API. With access to a rich array of news content spanning over 30 languages, this API serves as a gateway to the latest updates from the British Broadcasting Corporation (BBC). Seamlessly integrate trusted news sources into your applications, offering users a diverse and comprehensive view of current events. Empower your audience with timely and reliable information, curated by one of the most respected news organizations worldwide.

Requests Badge Latency Badge

BBC

BBC, British Broadcasting Corporation is a Trustable News Site. It has coverage of 30 languages.

API

Application Programming Interface(API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build or use such a connection or interface is called an API specification.

What is this API?

BBC News API is the API for serving the news from all the BBC Services according to your need. This API has a coverage of 30 Languages (All supported languages by BBC)!

How it works?

graph TD;
    yourpc["Your PC"]
    bbcweb["BBC Web"]
    api["API"]
    yourpc-- Request -->api;
    api-- Request-->bbcweb;
    bbcweb-- Response -->api;
    api-- Response -->yourpc;

Documentation

The official BBC News API documentation can be found here

Endpoints

URL Formation: https://bbc-api.vercel.app/<type>?lang=<language>

Types & Languages are in Endpoints.md

Wrapper

bbc-news for Python

The bbc-news Python wrapper provides convenient access to the BBC News API from your Python projects. It allows you to easily fetch news content and integrate it into your applications. You can install the wrapper via pip:

pip install bbc-news

Example usage in Python: Quick start with bbc-news

How to use?

Fetch our API URL with GET HTTP method! You can use any programming language to use our API. Here are code examples, how you can use our API in different language.

Python
With Wrapper
# pip install bbc-news

# Import the Library
import bbc

# Get the News for Bengali
news = bbc.news.get_news(bbc.Languages.Bengali)

# Get the Category Titles
categories = news.news_categories()

# Loop through the category titles
for category in categories:
    # Get the Category News
    section_news = news.news_category(category)

    # Loop through the news dictionary
    for news_dict in section_news:
        # Print the Title
        print(news_dict['title'])

        # Print the Image Link
        print(news_dict['image_link'])

        # Print the News Link
        print(news_dict["news_link"])
                
        # Print a Blank Line
        print("---")
With requests
# pip install requests
import requests

response = requests.get("https://bbc-api.vercel.app/news?lang=bengali").json()
print(response)
JavaScript (Node.js)
const axios = require('axios');

axios.get('https://bbc-api.vercel.app/news?lang=chinese')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });
JavaScript (Browser)
fetch('https://bbc-api.vercel.app/news?lang=turkish')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.log(error));
PHP
$response = file_get_contents('https://bbc-api.vercel.app/news?lang=spanish');
$data = json_decode($response);
print_r($data);
Ruby
require 'net/http'
require 'json'

uri = URI('https://bbc-api.vercel.app/news?lang=portuguese')
response = Net::HTTP.get(uri)
data = JSON.parse(response)
puts data
Java
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://bbc-api.vercel.app/news?lang=russian");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.connect();
            int responseCode = conn.getResponseCode();
            if (responseCode == 200) {
                Scanner scanner = new Scanner(url.openStream());
                String responseBody = scanner.useDelimiter("\\A").next();
                scanner.close();
                System.out.println(responseBody);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

NOTE: IF ANY ERROR ENCOUNTERED, FEEL FREE TO CREATE AN ISSUE

The response looks so messy?

The response is received in json format. So, it might look a bit messy but don't worry, just Paste the response in Json Formatter and press Process, it will show you a nice structured result!

Raw Response
{
   "status":200,
   "latest":{
      "title":"***与普京会晤:这场中俄元首会谈预料将带来什么?",
      "news_link":"https://www.bbc.com/zhongwen/simp/world-65011228",
      "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/1124F/production/_129032207_70993ea9-6b3a-47f8-ad2e-fb9056891843.jpg"
   },
   "Top story - Zhongwen":[
      {
         "title":"台积电赴德国设厂:为何引发**与欧盟“晶片外交”争议",
         "news_link":"https://www.bbc.com/zhongwen/simp/business-65010920",
         "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/111C9/production/_113598007_whatsubject.jpg"
      },
      {
         "title":"法国养老金抗议:一场马克龙政府注定难逃的危机?",
         "news_link":"https://www.bbc.com/zhongwen/simp/world-65011246",
         "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/7802/production/_129022703_parisprot.jpg"
      },
      {
         "title":"美国前总统特朗普发文称他预计将于周二被捕",
         "news_link":"https://www.bbc.com/zhongwen/simp/world-65005167",
         "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/97F7/production/_129030983_bcb1bb78fb380529961661a4e58750eab4235d14.jpg"
      },
      {
         "title":"国际刑事法院颁令拘捕普京,指控他犯下战争罪",
         "news_link":"https://www.bbc.com/zhongwen/simp/world-64998418",
         "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/F872/production/_129020636_gettyimages-1247187786.jpg"
      },
      {
         "title":"视频, 乌克兰战争:记者随军记录巴赫穆特的前线战场, 节目全长 5,53",
         "news_link":"https://www.bbc.com/zhongwen/simp/world-64991992",
         "image_link":"https://ichef.bbci.co.uk/images/ic/512xn/p0f9cl9n.jpg"
      },
      {
         "title":"“大而不倒”的瑞信股价暴跌 比硅谷银行倒闭更像“雷曼时刻”",
         "news_link":"https://www.bbc.com/zhongwen/simp/business-64976475",
         "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/1269B/production/_128991457_creditsuisse_reuters.jpg"
      },
      {
         "title":"**流亡商人郭文贵在美国被控诈骗10亿美元,北京低调回应",
         "news_link":"https://www.bbc.com/zhongwen/simp/world-64985642",
         "image_link":"https://ichef.bbci.co.uk/news/640/cpsprodpb/11B84/production/_97708527_capture.jpg"
      },
      {
         "title":"视频, 台积电创办人张忠谋表态支持美国对华晶片政策 称半导体业全球化已死, 节目全长 1,42",
         "news_link":"https://www.bbc.com/zhongwen/simp/chinese-news-64987302",
         "image_link":"https://ichef.bbci.co.uk/images/ic/512xn/p0f9b064.jpg"
      }
   ],
   "elapsed time":"0.00s",
   "timestamp":1679297348
}
Formatted Response

Formatted Response

In your code, you can get the value by calling the key.

{"key": "value"}

bbc-news-api's People

Contributors

sayad-uddin-tahsin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cphpi saurav1604

bbc-news-api's Issues

URLs are unreachable

Hey man,

I wanted to use your API endpoint https://bbc-api.tah3.repl.co/bengali/news but it's giving me 404 page not found.

To Reproduce
Go to any URL of https://bbc-api.tah3.repl.co/<language>/<type> and it'll give same behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.