PHP code example of gfargo / newsapi

1. Go to this page and download the library: Download gfargo/newsapi 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/ */

    

gfargo / newsapi example snippets


composer 

\NewsAPI\Client::setAccessToken('276537c6a3824cdd9eae393c024ff732');

// All articles featuring the keyword 'Open Source'
$request = NewsAPI\Client::query( 'everything', [ 'q' => 'Open Source' ] );

// Top headlines for articles featuring the keyword 'Technology'
$request = NewsAPI\Client::query( 'top', [ 'q' => 'Technology' ] );

// Top articles from 'Business' category
$request = NewsAPI\Client::query( 'top', [ 'category' => 'business' ] );

$request = NewsAPI\Client::query( 'top', [ 'category' => 'business' ] );

$request->status_code             // int(200)
$request->headers['content-type'] // string(31) "application/json; charset=utf-8"
$request->url                     // string(54) "https://newsapi.org/v2/top-headlines?category=business"
$request->body                    // string(14385) "{...}"