title: Google Short URL API: Forbidden
body: <p>I have what I <em>think</em> is correctly written code yet whenever I try and call it I'm getting permission denied from Google.</p>
  
  <pre><code>file_get_contents(https://www.googleapis.com/urlshortener/v1/url): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
  </code></pre>
  
  <p>This isn't a rate limit or anything as I currently have zero ever used...  </p>
  
  <p>I would have thought this is due to an incorrect API key but I've tried resetting it a number of times. There isn't some downtime while the API is first applied is there? </p>
  
  <p>Or am I missing a header setting or something else just as small? </p>
  
  <pre><code>public function getShortUrl()
  {
      $longUrl = "http://example.com/";
      $apiKey = "MY REAL KEY IS HERE";
  
      $opts = array(
          'http' =&gt;
              array(
                  'method'  =&gt; 'POST',
                  'header'  =&gt; "Content-type: application/json",
                  'content' =&gt; json_encode(array(
                      'longUrl' =&gt; $longUrl,
                      'key'     =&gt; $apiKey
                  ))
              )
      );
  
      $context = stream_context_create($opts);
  
      $result = file_get_contents("https://www.googleapis.com/urlshortener/v1/url", false, $context);
  
      //decode the returned JSON object
      return json_decode($result, true);
  }
  </code></pre>