Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:33:06+00:00 2026-06-15T02:33:06+00:00

I am using following code in my Android code, from here https://developers.google.com/drive/v2/reference/files/get Everthing is

  • 0

I am using following code in my Android code, from here https://developers.google.com/drive/v2/reference/files/get

Everthing is ok, the file.getDownloadUrl() is not null, and is a really long URL.

But I am getting error 401 when getting the HttpResponse resp.

What is the problem?

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.

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:

  /**
       * 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 && file.getDownloadUrl().length() > 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;
        }
      }

LogCat:

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&e=download&gd=true
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:33:08+00:00Added an answer on June 15, 2026 at 2:33 am

    Make sure the parameter service is the instance of Drive you have authorized. If it’s not the case, buildGetRequest can’t add the authorization header because it does not know it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to post data from an android app to
I am using following code to get bitmap from url. This function is used
I'm following the following tutorial for Facebook Connect: https://developers.facebook.com/docs/mobile/android/build/ And attempting to allow my
i am using following code. <RelativeLayout android:layout_width=310dp android:layout_height=70dp android:layout_below=@+id/UIReportView android:layout_marginLeft=4dp android:layout_marginTop=2dp android:background=@drawable/small_corners > small_corners
Using following code I try to get updated list of checkbuttons' corresponding text values,
I am saving data from Android device to MySQL. My code works fine using
I am using the following code in android virtual Machine try{ HttpClient httpclient =
I am following this question: How to get rss feeds android? And I'm using
Aloha, I've been following the guidelines here: http://developer.android.com/resources/tutorials/testing/helloandroid_test.html To create some simple test cases
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.