I can not understand how to make a request for all the columns in the document using the Google Drive API. In the manual, I looked at an example request and tried to create my own.

I have a document and I am trying to request a page from it from the "Tasks" page (i.e. all its columns). The result was such a request:

https://sheets.googleapis.com/v4/spreadsheets/1PtiSLIP70hTB8yTp90ciyOVKzWXqqH1d7x-3s2cTdLg/values/Задачи 

This is how I try to execute it (this implementation of the thread is only for the first time):

 new Thread(() -> { try { URL sheetUrl = new URL("https://sheets.googleapis.com/v4/spreadsheets/1PtiSLIP70hTB8yTp90ciyOVKzWXqqH1d7x-3s2cTdLg/values/Задачи"); HttpURLConnection sheetConnection = (HttpURLConnection) sheetUrl.openConnection(); if (sheetConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader in = new BufferedReader(new InputStreamReader(sheetConnection.getInputStream())); String responce = ""; String inputLine; while ((inputLine = in.readLine()) != null) responce += inputLine; in.close(); Log.i(TAG, "responce = " + responce); } else { Log.i(TAG, "Ответа нет"); } } catch (Exception e) { throw new RuntimeException(e); } }).start(); 

And in my log it displays "no answer".


What is my mistake and how to fix it?

    1 answer 1

    The problem is that you, without going through the authorization procedure, are trying to execute the request, and the method:

     sheetConnection.getResponseCode() 

    returns 403 , and the entire JSON returned by your request looks like this:

     { "error": { "code": 403, "message": "The request cannot be identified with a client project. Please pass a valid API key with the request.", "status": "PERMISSION_DENIED" } } 

    You can read more about authorization and access keys at the link: Authorize Requests .

    • one
      @ bukashka101, Even if your file is visible to everyone ( public ), then to access it through the API, you need an API key . From the browser you can see it, because you are logged in. I tried to go (in the browser) to the link you specified - in response, I get the above JSON . - post_zeew