Uploading files to Google Cloud Storage using JSON API, Error 401 Unauthorized
<p>I am trying to figure out how to use the <code>JSON API</code> in Android to upload images to <code>Google Cloud Storage</code> but the documentation for doing so seems to be very limited.</p>

<p>The problem I am having I believe is getting the correct API key authentication. The images that are uploaded are images that are considered public but only public to the users of my app so reading <a href="https://cloud.google.com/storage/docs/json_api/v1/how-tos/authorizing#APIKey" rel="noreferrer">Authorize Requests</a> documentation says that I do not need to provide an OAuth key for public data and I can just send an API key</p>

<blockquote>
  <p>Public API access: A request that does not provide an OAuth 2.0 token
  must send an API key. The key identifies your project and provides API
  access, quota, and reports.</p>
</blockquote>

<p>so I went to my console created a key <code>(API Manager/Credentials/Create Credentials/API Key)</code> from my <code>SHA1</code> of my debug and production keystore's.</p>

<p>these API keys are correct because they are used with other google services like <code>google sign-in</code> and they work fine.</p>

<p>When I try to make a request to start a resumable upload this is what I do</p>

<pre><code>String sUrl = "https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=resumable&amp;name="+mImgName;
URL url = new URL(sUrl);
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setRequestProperty("Authorization","AIzaSyDT....");
urlConnection.setRequestProperty("X-Upload-Content-Type","image/png");
urlConnection.setRequestProperty("X-Upload-Content-Length",String.valueOf(fileSize));
urlConnection.setRequestMethod("POST");
</code></pre>

<p>however I get back <code>Error 401 Unauthorized</code> so I am assuming it is a problem with the key I am sending.</p>

<p>I also saw at the end of the <code>Authorize Requests</code> document that it states I can put my key as a parameter of the request url</p>

<blockquote>
  <p>After you have an API key, your application can append the query
  parameter key=yourAPIKey to all request URLs.</p>
</blockquote>

<p>so I dont know if I am suppose to do that or have the <code>Authorization</code> property set in the request or both?</p>

<p>So is the key I created the wrong type of key or is there something I am missing here?</p>