Permabanned
- Joined
- 9 Aug 2008
- Posts
- 35,708
I am just learning API's and PHP, Here is an example;
There are 38 articles in this API currently. (The one above is the first example from the api). I want to be able to call a random topic using php but it's not working. Does anyone know why? (I could give someone the api key in here if they would be willing to test to see if they could pull data from it.
Any help would be appreciated, I just need to be able to pull a random topic from the API news headlines if possible..
Example Pull Data From API: https://i.imgur.com/WgaYVZ3.png
Code:
http://newsapi.org/v2/top-headlines?country=gb&apiKey=api_key_here
Code:
{"status":"ok","totalResults":38,"articles":[{"source":{"id":null,"name":"The Sun"},"author":"Holly Christodoulou","title":"UK coronavirus death toll rises to at least 40,726 after 129 more die in England in 24 hours - The Sun","description":"","url":"http://www.thesun.co.uk/news/11819311/coronavirus-deaths-uk-england-total-daily/","urlToImage":"https://www.thesun.co.uk/wp-content/uploads/2020/06/NINTCHDBPICT000587963546.jpg?strip=all&quality=100&w=1200&h=800&crop=1","publishedAt":"2020-06-09T16:44:07Z","content":"CORONAVIRUS deaths in the UK have risen to 40,883 after 286 more people died - although the true number is likely to be much higher.\r\nPositive Covid-19 infections have also risen by 1,387 to 289,140,… [+3102 chars]"},
There are 38 articles in this API currently. (The one above is the first example from the api). I want to be able to call a random topic using php but it's not working. Does anyone know why? (I could give someone the api key in here if they would be willing to test to see if they could pull data from it.
Code:
<?php
$content = file_get_contents("http://newsapi.org/v2/top-headlines?country=gb&apiKey=api_key_here");
$result = json_decode($content);
print_r( $articles->source->name);
?>
Any help would be appreciated, I just need to be able to pull a random topic from the API news headlines if possible..
Example Pull Data From API: https://i.imgur.com/WgaYVZ3.png