Problems getting the Tokenprice using PHP

Sorry for the messy code in advance. I want to write a code which returns me infos from the official Blizzard API, which I can then print out on my homepage. The code doesn’t throw any errors but it doesn’t print out something either. For Starters:

  1. I would also prefer using CURL, but my homepage is on a Wordpress Hosting Site and I don’t know how to install the CURL Library that way
  2. allow_furl_open is on
 $url = "https://eu.battle.net/oauth/token"; 

 $data = array('grant_type' => 'client_credentials');

 //HTTP options
 $opts = array('http' =>
 array(
     'method'    => 'POST',
     'header'    => array ('Content-type: multipart/form-data', 'Authorization: Basic ' . 
 base64_encode("$client_id:$client_pass")),
     'content' => json_encode($data)
 )
);

//Do request
 $context = stream_context_create($opts);

 $json = file_get_contents($url, false, $context);

 $result = json_decode($json, true);

 $accessToken = $json['access_token'];







 $tokenURL = "https://us.api.blizzard.com/data/wow/token/?namespace=dynamic-eu";
 $opts2 = array('http' =>
            array(
                'method' => 'GET',
                'header' => array('Content-type: multipart/form-data', 'Authorization: Bearer ' . $accessToken),
                )
            );

$context2 = stream_context_create($opts2);
$json2 = file_get_contents($tokenURL,false,$context2);

$result2 = json_decode($json2, true);
$tokenprice = $result2['price'];

echo "<p>Tokenpreis:" .$tokenprice. "</p>";

I didn’t add the $client_id and $client_pass into the code snippet, but this exists obviously. I used this PHP CURL Snippet as template. Anyone got an idea what I am doing wrong? I am loosing my mind right here

Probably you are using the wrong subdomain us with the namespace eu. The correct URL would be one of those:

  • https://eu.api.blizzard.com/data/wow/token/?namespace=dynamic-eu
  • https://us.api.blizzard.com/data/wow/token/?namespace=dynamic-us