PHPackages                             kirtusj/newsapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kirtusj/newsapi

ActiveProject[API Development](/categories/api)

kirtusj/newsapi
===============

A PHP Library for utilizing the NewsApi service

1.0.12(7y ago)08MITPHPPHP &gt;=7.1

Since Jan 11Pushed 7y agoCompare

[ Source](https://github.com/KirtusJ/newsapi-php)[ Packagist](https://packagist.org/packages/kirtusj/newsapi)[ RSS](/packages/kirtusj-newsapi/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

newsapi-scraper
===============

[](#newsapi-scraper)

A PHP Package for the [NewsAPI](https://newsapi.org/docs/) utility

Installation
============

[](#installation)

```
composer require kirtusj/newsapi

```

Usage
=====

[](#usage)

```
require __DIR__.'/vendor/autoload.php';
use kirtusj\newsapi\Scraper;
$newsapi = new Scraper($api_key="your_api_key_here");

```

### everything

[](#everything)

```
$all_articles = $newsapi->get_everything(array(
						'q' => 'bitcoin',
						'sources' => 'bbc-news,the-verge',
						'domains' => 'bbc.co.uk,techcrunch.com',
						'language' => 'en',
						'sortBy' => 'relevancy',
						'page' => 2));

```

### top

[](#top)

```
$top_articles = $newsapi->get_top(array(
					'q' => 'bitcoin',
					'sources' => 'bbc-news, the-verge',
					'category' => 'business',
					'language' => 'en',
					'country' => 'us'));

```

### sources

[](#sources)

```
$sources = $newsapi->get_sources(array());

```

The information held in these variables can be used however you like.

Example
=======

[](#example)

### input

[](#input)

```
$query = "Canada";
$page = 1;
$pageSize = 3;
$language = 'en';

$top_articles = $newsapi->get_top(array('q' => $query, 'page' => $page, 'pageSize' => $pageSize, 'language' => $language));

echo $top_articles;

```

### output

[](#output)

```
{"status":"ok","totalResults":30,"articles":[{"source":{"id":"nhl-news","name":"NHL 	News"},"author":null,"title":"'Hockey Night in Canada': 5 Storylines","description":"The Boston Bruins and Toronto Maple Leafs will play for the fourth and final time during the regular season at Scotiabank Arena as part of a \"Hockey Night in Canada\" doubleheader on Saturday (7 p.m. ET; NHLN, CBC, SN1, CITY, NESN, NHL.TV). The home team has w…","url":"https://www.nhl.com/news/hockey-night-in-canada-5-storylines-january-12/c-303810292","urlToImage":"https://nhl.bamcontent.com/images/photos/303810922/1024x576/cut.jpg","publishedAt":"2019-01-13T00:56:28.3635098Z","content":"The Boston Bruins and Toronto Maple Leafs will play for the fourth and final time during the regular season at Scotiabank Arena as part of a \"Hockey Night in Canada\" doubleheader on Saturday (7 p.m. ET; NHLN, CBC, SN1, CITY, NESN, NHL.TV). The home team has w… [+4309 chars]"}]}

```

Endpoints
=========

[](#endpoints)

Endpoints return a JSON Object based on the input you give them

get\_top
--------

[](#get_top)

```
"top" : "https://newsapi.org/v2/top-headlines"

```

### options

[](#options)

q, sources, language, country, pageSize, page

get\_everything
---------------

[](#get_everything)

```
"everything" : "https://newsapi.org/v2/everything"

```

### options

[](#options-1)

q, sources, language, domains, excludeDomains, from, to, sort, pageSize, page

get\_sources:
-------------

[](#get_sources)

```
 "sources" : "https://newsapi.org/v2/sources"

```

### options

[](#options-2)

category, country, language

Input
=====

[](#input-1)

### countries:

[](#countries)

```
  'ae','ar','at','au','be','bg','br','ca','ch','cn','co','cu','cz','de','eg','fr','gb','gr','hk',
  'hu','id','ie','il','in','it','jp','kr','lt','lv','ma','mx','my','ng','nl','no','nz','ph','pl',
  'pt','ro','rs','ru','sa','se','sg','si','sk','th','tr','tw','ua','us','ve','za'

```

### languages:

[](#languages)

```
  'ar','en','cn','de','es','fr','he','it','nl','no','pt','ru','sv','ud'

```

### categories:

[](#categories)

```
'business', 'entertainment', 'general', 'health', 'science', 'sports', 'technology'}

```

### sortBy :

[](#sortby-)

```
'relevancy','popularity','publishedAt'

```

### to and from :

[](#to-and-from-)

\[from\] date and \[to\] date Must be structured in YYYY-MM-DD format

### Input types

[](#input-types)

```
  "q" : string
  "sources" : string
  "language" : string
  "country" : string
  "pageSize" : int
  "page" : int
  "domains" : string
  "date" : string
  "sortBy" : string
  "category" : str

```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

2678d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a0f2d33293330c219815f385c1965458501295fe068092e3510ba829c3ee427?d=identicon)[kirtusj](/maintainers/kirtusj)

---

Tags

jsonapiqueryscrape newsnewsapi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kirtusj-newsapi/health.svg)

```
[![Health](https://phpackages.com/badges/kirtusj-newsapi/health.svg)](https://phpackages.com/packages/kirtusj-newsapi)
```

###  Alternatives

[serpwow/google-search-results

Google Search Results PHP package via SerpWow.com

1931.8k1](/packages/serpwow-google-search-results)[nathanmac/parser

Simple PHP Parser Utility Library for API Development

2151.0M3](/packages/nathanmac-parser)[getkirby/kql

Kirby Query Language

15124.3k](/packages/getkirby-kql)[joskolenberg/laravel-jory

Create a flexible API for your Laravel application using json based queries.

4513.5k](/packages/joskolenberg-laravel-jory)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.0k](/packages/nilportugues-jsonapi-bundle)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.6M3](/packages/cloudcreativity-json-api-testing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
