1. Go to this page and download the library: Download murat-yuksel/news-api-php 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/ */
murat-yuksel / news-api-php example snippets
$client = new \NewsApi\Client();
$request = new \NewsApi\Request\TopHeadlinesRequest();
$request->apiKey = getenv('NEWS_API_KEY');
$request->q = 'turkey';
$request->category = 'business';
$result = $client->topHeadlines($request);
function sources(\NewsApi\Client $client)
{
$request = new \NewsApi\Request\SourcesRequest();
$request->apiKey = getenv('NEWS_API_KEY');
$request->language = 'en';
$request->category = 'entertainment';
return $client->sources($request);
}
Route::get('/', function (\NewsApi\Client $client) {
$request = new \NewsApi\Request\EverythingRequest();
$request->apiKey = env('NEWS_API_KEY');
$request->q = 'turkey';
$sources = $client->everything($request);
var_dump($sources);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.