nonsoniyi/the-guardian-api-client

PHP wrapper for the guardian APIs

Maintainers

👁 omoniyi

Package info

github.com/niyiomotoso/the-guardian-api-php-client

pkg:composer/nonsoniyi/the-guardian-api-client

Statistics

Installs: 1 388

Dependents: 1

Suggesters: 0

Stars: 6

Open Issues: 0

v1.0.4 2024-05-14 21:04 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 0ed9a81f4ad7734e453088267225806a8d319b70

apiwrapperThe Guardian

This package is auto-updated.

Last update: 2026-06-15 01:40:05 UTC


README

PHP client library for the Guardian APIs. See documentation here. All available API modules are supported - Content, Tags, Sections, Editions, and Single Item.

Installation

You can install this package with composer using the command below

 composer require nonsoniyi/the-guardian-api-client

Get API key

Sign up for an API key here

Making Requests

The primary Guardian\GuardianAPI class is a factory class that creates objects for each of the API modules, allowing you to make requests to any of them with your desired request parameters. You have to first create an object for it, then access your desired API module via the object. See the code snippets below:

$api = new Guardian\GuardianAPI(THE_GUARDIAN_API_KEY);

For Content:

$response = $api->content()
 ->setQuery("12 years a slave")
 ->setTag("film/film,tone/reviews")
 ->setFromDate(new DateTimeImmutable("01/01/2010"))
 ->setToDate(new \DateTimeImmutable())
 ->setShowTags("contributor")
 ->setShowFields("starRating,headline,thumbnail,short-url")
 ->setOrderBy("relevance")
 ->fetch();

For Tags:

$response = $api->tags()
 ->setQuery("apple")
 ->setSection("technology")
 ->setShowReferences("all")
 ->fetch();

For Sections:

$response = $api->sections()
 ->setQuery("business")
 ->fetch();

For Editions:

$response = $api->editions()
 ->setQuery("uk")
 ->fetch();

For Single Item:

$response = $api->singleItem()
 ->setId("/sport/2022/oct/07/cricket-jos-buttler-primed-for-england-comeback-while-phil-salt-stays-focused")
 ->setShowStoryPackage(true)
 ->setShowEditorsPicks(true)
 ->setShowMostViewed(true)
 ->setShowRelated(true)
 ->fetch();

Community support

You can reach out to us on the Google Group here https://groups.google.com/g/guardian-api-talk for support