Sunday, October 25

NewsApi.org

Here is the news api php for newsapi.org This php script is running on newsverifier.com/test in it’s raw form.

It is running here https://newsverifier.com/current-news/ where we have integrated it into wordpress under an api key for developers.

We are developing wordpress integration and plugin in hopes of using this kind of system to prevent the spread of fake news.

The following script is the property of NewsVerifier Media and is licensed to anyone for development or any other purpose. There is no warranty and by using testing installing or executing this script in any way is at your own risk.

<?
$json_string = 'https://newsapi.org/v2/top-headlines?country=us&apiKey=YOUR-API-KEY-HERE';
$jsondata = file_get_contents($json_string);

$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($jsondata, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

$id = 'id';
$name = 'name';
$author = 'author';
$title = 'title';
$description = 'description';
$url = 'url';
$urlToImage = 'urlToIamge';
$publishedAt = 'publishedAt';
$content = 'content';



foreach ($jsonIterator as $key => $val) {
$i = 0;


      if(is_array($val)) {
echo "\n";
     } else {
        if($key == "id")
           {$id = $val;}
        if($key == "name")
           {$name = $val;}              
        if($key == "author")
           {$author = $val;}
        if($key == "title")
           {$title = $val;}
        if($key == "description")
           {$description = $val;}
        if($key == "url")
           {$url = $val;}
        if($key == "urlToImage")
           {$urlToImage = $val;}
        if($key == "publishedAt")
           {$TimeStamp = $val;}
        if($key == "content")
           {$content = $val; $i++;}

 


if($content != 'content')
{
  $mycontent = '<center><table border="0" width="50%"><tr><td><a href="'.$url.'"><font size="+3">'.$title.'</a></font></td></tr><tr><td><table><tr><td><img src="'.$urlToImage.'" width="750" height="500"></td><td valign="top"><font size="+1"><b>'.$content.'<p><a href="'.$url.'">Read this article here</a></b></font></td></tr></table></td></tr><tr><td>Time Stamp '.$TimeStamp.'</td></tr></table></center></p><p>&nbsp;<p>&nbsp;';
}
 if($i == 1)
   {
    echo $mycontent;
 }
}
}
?>