PHPackages                             kostikpenzin/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. kostikpenzin/newsapi

ActiveLibrary[API Development](/categories/api)

kostikpenzin/newsapi
====================

A PHP client for NewsApi

v1.0(3y ago)034MITPHPPHP &gt;=7.3

Since Dec 28Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kostikpenzin/newsapi-php)[ Packagist](https://packagist.org/packages/kostikpenzin/newsapi)[ RSS](/packages/kostikpenzin-newsapi/feed)WikiDiscussions main Synced 1mo ago

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

NewsAPI-PHP
-----------

[](#newsapi-php)

[![Latest Stable Version](https://camo.githubusercontent.com/0ff600ed6c7d9f4e57473da6aee42b7c4f7a826408e4aa972a650b21d439a642/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7374696b70656e7a696e2f6e6577736170692f762f737461626c65)](https://packagist.org/packages/kostikpenzin/newsapi)[![Total Downloads](https://camo.githubusercontent.com/0a1a821fb98ca679e084d94e4c512155b20ee2ef248f242798121d539f64569a/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7374696b70656e7a696e2f6e6577736170692f646f776e6c6f616473)](https://packagist.org/packages/kostikpenzin/newsapi)[![Latest Unstable Version](https://camo.githubusercontent.com/18c38127228d931d2271a74976895e2a948587f62112a19954faa5a523d0bdd7/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7374696b70656e7a696e2f6e6577736170692f762f756e737461626c65)](https://packagist.org/packages/kostikpenzin/newsapi)[![License](https://camo.githubusercontent.com/4a72517bd817318f72586773078e085a4f0d0865a48f6d6abf0bf3bd721dede6/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7374696b70656e7a696e2f6e6577736170692f6c6963656e7365)](https://packagist.org/packages/kostikpenzin/newsapi)[![Monthly Downloads](https://camo.githubusercontent.com/2dce2ae4ba6facec9690db01e35ce16f52ec89186a7791c4675dcf97ccc155b5/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7374696b70656e7a696e2f6e6577736170692f642f6d6f6e74686c79)](https://packagist.org/packages/kostikpenzin/newsapi)

A PHP client for the [News API](https://newsapi.org/docs/get-started).

### Installation

[](#installation)

Available for installation on packagist using composer.

```
composer require kostikpenzin/newsapi

```

### Usage

[](#usage)

After installation and and `require`ing `vendor/autoload.php` file in your project,

Get Your API key from [here](https://newsapi.org/register)

```
use kostikpenzin\NewsApi\NewsApi;
.
.
.
$newsapi = new NewsApi($your_api_key);
```

### Get TopHeadLines

[](#get-topheadlines)

```
$newsapi->getTopHeadlines($q, $sources, $country, $category, $page_size, $page);

* $q : Keywords or a phrase to search for.

* $sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from.
            Use the getSources() method to locate these programmatically or look at the sources index.
            Note: you can't mix this param with the country or category params.

* $country: The 2-letter ISO 3166-1 code of the country you want to get headlines for.
            Use the getCountries() method to locate these programmatically.
            Note: you can't mix this param with the sources param.

* $category: The category you want to get headlines for. Use the getCategories() method to locate these programmatically.
             Note: you can't mix this param with the sources param.

* $page_size: The number of results to return per page (request). 20 is the default, 100 is the maximum.

* $page: Use this to page through the results if the total results found is greater than the page size.

Returns JSON object is successful or throws excpetions if invalid data or unsuccessful request.

```

### Get Everything

[](#get-everything)

```
$newsapi->getEverything($q, $sources, $domains, $exclude_domains, $from, $to, $language, $sort_by,  $page_size, $page);

* $domains: A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to.

* $exclude_domains: A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to remove from the results.

* $from: A date and optional time for the oldest article allowed.
         This should be in ISO 8601 format (e.g. 2018-11-16 or 2018-11-16T16:19:03)
         Default: the oldest according to your plan.

* $to: A date and optional time for the newest article allowed.
       This should be in ISO 8601 format (e.g. 2018-11-16 or 2018-11-16T16:19:03)
       Default: the newest according to your plan.

* $language: The 2-letter ISO-639-1 code of the language you want to get headlines for.
             Possible options: ar de en es fr he it nl no pt ru se ud zh .
             Default: all languages returned. Use the getLanguages() method to locate these programmatically.

* $sort_by: The order to sort the articles in. Use the getSortBy() method to locate these programmatically.

Returns JSON object is successful or throws excpetions if invalid data or unsuccessful request.

```

### Get New Sources

[](#get-new-sources)

```
$newsapi->getSources($category, $language, $country)

Returns JSON object is successful or throws excpetions if invalid data or unsuccessful request.

```

### Get Countries

[](#get-countries)

```
$newsapi->getCountries()

Returns an array of allowed countries

```

### Get Languages

[](#get-languages)

```
$newsapi->getLanguages()

Returns an array of allowed languages

```

### Get Categories

[](#get-categories)

```
$newsapi->getCategories()

Returns an array of allowed categories

```

### Get SortBy

[](#get-sortby)

```
$newsapi->getSortBy()

Returns an array of allowed sort_by

```

### CONTRIBUTORS

[](#contributors)

This package is authored by Joseph Cobhams.

### TODO

[](#todo)

Write more unit tests, mocks and stubs.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

1229d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91e9cbcca0b902019fbc065d783f7953d99b744cb4a209e43167be3ba8bf6367?d=identicon)[penzin85](/maintainers/penzin85)

---

Top Contributors

[![kostikpenzin](https://avatars.githubusercontent.com/u/5538990?v=4)](https://github.com/kostikpenzin "kostikpenzin (3 commits)")

---

Tags

newsapi

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[jcobhams/newsapi

A PHP client for NewsApi

4322.7k](/packages/jcobhams-newsapi)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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