Reputation: 579
After running the code below, I get a empty page. I would like to get the price from bids and asks, but I can't get any data.
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
$url="https://api.gdax.com/products/BTC-EUR/book";
$json = @file_get_contents($url);
if($json){
$data = @json_decode($json, TRUE);
print_r($data);
}
?>
Upvotes: 0
Views: 204
Reputation: 3627
The issue is that this API appears to be blocking these types of requests. They will not allow users that do not have a useragent set.
The fastest way to get around this is to set a UserAgent within PHP, which you can do by putting this code above your call to the API:
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20100101 Firefox/9.0');
However, I would recommend using CURL instead of file_get_contents, as file_get_contents is often restricted by server configuration.
Upvotes: 4