PHP code example of nonsoniyi / the-guardian-api-client

1. Go to this page and download the library: Download nonsoniyi/the-guardian-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nonsoniyi / the-guardian-api-client example snippets


$api = new Guardian\GuardianAPI(THE_GUARDIAN_API_KEY);

$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();

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

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

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

$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();