Saurabh Gandhe I bring your ideas to life!

PHP Wrapper for NewsAPI.org

P

I came across a nice website NewsAPI.org that gives you access to news from around the world. You can filter based on country, language and category.

Check it out: https://newsapi.org/

Documentation: https://newsapi.org/docs

They didn’t have a PHP wrapper, and I was getting bored, so I scribbled a wrapper using curl to use it in PHP applications.

Add the API Key Generated using a Free Account(it has some limitations).

Look at the documentation to see the usage, as all I do is pass the same parameters to the curl request.

include 'config.php'; #set the api key here#
$newsAPIClient = new newsAPIClient;
$topHeadlines = $newsAPIClient->getSources(array('country' => 'in'));
$topHeadlines = $newsAPIClient->getEverything(array('q' => 'bitcoin', 'pageSize' => 5));

You can download the sourcecode here.

There is no warranty associated and is not intended for production use. I would add some comments and format code before use.

By Saurabh
Saurabh Gandhe I bring your ideas to life!

Contact Hands-on DevOps with Azure/AWS Experience

Recent Posts

Categories