title: Download file error [com.google.api.client.http.HttpResponseException: 401 Unauthorized]
body: <p>I am using following code in my Android code, from here <a href="https://developers.google.com/drive/v2/reference/files/get" rel="nofollow">https://developers.google.com/drive/v2/reference/files/get</a></p>
  
  <p>Everthing is ok, the file.getDownloadUrl() is not null, and is a really long URL.</p>
  
  <p>But I am getting error 401 when getting the HttpResponse resp.</p>
  
  <p>What is the problem? </p>
  
  <p>I assume I am already authorized because I can list all my files in my GoogleDrive, get the fileId and even the file.getDownloadUrl(). My OAuth2.0 scope is DRIVE.</p>
  
  <pre><code>11-26 06:40:37.614: W/System.err(15750): com.google.api.client.http.HttpResponseException: 401 Unauthorized
  11-26 06:40:37.614: W/System.err(15750):    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1062)
  </code></pre>
  
  <p>CODE:</p>
  
  <pre><code>  /**
         * Download a file's content.
         *
         * @param service Drive API service instance.
         * @param file Drive File instance.
         * @return InputStream containing the file's content if successful,
         *         {@code null} otherwise.
         */
        private static InputStream downloadFile(Drive service, File file) {
          if (file.getDownloadUrl() != null &amp;&amp; file.getDownloadUrl().length() &gt; 0) {
            try {
              HttpResponse resp =
                  service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
                      .execute();  //--ERROR HERE--
              return resp.getContent();
            } catch (IOException e) {
              // An error occurred.
              e.printStackTrace();
              return null;
            }
          } else {
            // The file doesn't have any content stored on Drive.
            return null;
          }
        }
  </code></pre>
  
  <p>LogCat:</p>
  
  <pre><code>11-26 06:50:04.638: I/fileId(16350): 0B2PmmdZsG0kJUTFNcWNaam9KLVE
  
  11-26 06:50:07.896: I/file.getDownloadUrl()(16350): https://doc-0s-8g-docs.googleusercontent.com/docs/securesc/3l0k423jsgncap9ihfdfv9kb388vqac9/glhd2gbkatjpv4cb60383pc8b127o0l2/1353873600000/11834093636053924840/11834093636053924840/0B2PmmdZsG0kJUTFNcWNaam9KLVE?h=16653014193614665626&amp;e=download&amp;gd=true
  </code></pre>