Deprecated: Calling get_class() without arguments is deprecated in /var/www/html/wp-includes/class-wp-http.php on line 329 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/class-wp-http.php:329) in /var/www/html/wp-includes/feed-rss2.php on line 8 Projects – Saurabh Gandhe https://saurabhgandhe.com I bring your ideas to life! Mon, 09 Sep 2019 21:26:25 +0000 en-US hourly 1 https://wordpress.org/?v=6.3.1 144541061 PHP Wrapper for NewsAPI.org https://saurabhgandhe.com/php-wrapper-for-newsapi-org/ Mon, 09 Sep 2019 21:21:02 +0000 https://saurabhgandhe.com/?p=374 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.

]]>
374