Skip to content

Instantly share code, notes, and snippets.

@elkangaroo
Created December 12, 2016 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elkangaroo/89a4bae00a2d19901ec9be34005b08cc to your computer and use it in GitHub Desktop.
Save elkangaroo/89a4bae00a2d19901ec9be34005b08cc to your computer and use it in GitHub Desktop.
<?php
const API_KEY = 'xxx';
$url = 'http://www.giantbomb.com/api/game/3030-4725/?api_key=' . API_KEY . '&field_list=name&format=json';
// using file_get_contents
$context = stream_context_create(['http' => ['user_agent' => 'API Test UA']]);
$response = file_get_contents($url, false, $context);
echo $response;
// using curl
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'API Test UA');
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment