Trying to store from an API some json data to MySQL.
I am using this simple php code
<?php
require 'config.php';
$url = "https://www.widgety.co.uk/api/operators.json?app_id<key>&token<token>";
$string = file_get_contents('https://www.widgety.co.uk/api/operators.json?app_id<key>&token=<token>');
$arr = json_decode($string, true);
foreach($arr as $item){
$title = $item['operator']['title'];
$id = $item['operator']['id'];
$profile_image = $item['operator']['profile_image_href'];
$cover_image = $item['operator']['cover_image_href'];
$href = $item['operator']['href'];
$html_href = $item['operator']['html_href'];
$unique_text = $item['operator']['unique_text'];
$reasons_to_book = $item['operator']['reasons_to book'];
$members = $item['operator']['members_club'];
$brochures = $item['operator']['brochures'];
$ships = $item['operator']['ships'];
$video_url = $item['operator']['video_url'];
$query("INSERT INTO operator (title, id, profile_image) VALUES('$title', '$id', '$profile_image')");
$dataatodb = mysqli_query($con, $query);
if(!$dataatodb){
die("Error" . mysqli_error($con));
}
}
?>
But I get this error
Warning: file_get_contents(app_id<key>&token<token>): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in C:\xampp\htdocs\mypage\dataload.php on line 6
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\mypage\dataload.php on line 9
What am I doing wrong?
PS On URL i have the right app_id and token