title: How to GET data from API and show it on PHP page?
body: <p>I want to make a page on my website with some data from an API. The website is made with Wordpress.</p>
  
  <p>I have tried with various codes/functions found on web but with no success.</p>
  
  <p>The API requires me to login by user, pass or token (I prefer token).</p>
  
  <p>I'm new to API and PHP and I don't even know where to start.</p>
  
  <p>If anyone used it before, I want to take data from Exoclick API.</p>
  
  <p>From the API Interface on Exoclick I can see that the request is made with curl, I never used it before and I prefer not to. Here is an example</p>
  
  <pre><code>curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer tokenhere' 'https://api.exoclick.com/v2/statistics/publisher/country?'
  </code></pre>
  
  <p>From the API manual, I found this code for login, but placing it in a random page for test, it just crashes my website:</p>
  
  <pre><code>&lt;?php
  
          // Include Request and Response classes
  
          $url = 'https://api.exoclick.com/v2/login';
  
          $params = array(
                  'api_token'  =&gt; 'tokenhere'
              );
  
          // Create a new Request object
          $request = new Request($url, 'POST', $params);
  
          // Send the request
          $request-&gt;send();
  
          // Get the Response object
          $response = $request-&gt;getResponse();
  
          if($response-&gt;getStatusCode() == 200) {
  
              // Retrieve the session token details
              $token = $response-&gt;getBodyDecoded();
  
              print_r($token);
          }
          else {
  
              echo $response-&gt;getStatusCode() . PHP_EOL;
              echo $response-&gt;getReasonPhrase() . PHP_EOL;
              echo $response-&gt;getBody() . PHP_EOL;
          }
      ?&gt;
  </code></pre>