17

Using Google Sheets API v4, I am looking to get the list of spreadsheets attached to my account. I did much research but have not found any solutions for that.

Gaurav Ashara
  • 462
  • 2
  • 6
  • 16

4 Answers4

12

The v4 API doesn't offer a way to list spreadsheets. You'll need to use the Drive API. The Migrate from a previous API page has some details on how to do use the Drive API to do it.

Sam Berlin
  • 3,603
  • 12
  • 23
  • 2
    I've been searching this for 6 hours, But Hey @Sam But how read this response, Looks like XML is not formatted well. Can I get JSON response – Kiran Koravi May 04 '17 at 12:13
9

To get list of all files of specific type, you can use drive API v3. Below is an example to get all sheets from drive of authenticated user.

drive.files.list({
    q: "mimeType='application/vnd.google-apps.spreadsheet'",
    fields: 'nextPageToken, files(id, name)'
}, (err, response) => {
    //Your code
})

You can pass file type in MIME type as 'q' parameter. You can get list of drive MIME types here.

source: https://developers.google.com/sheets/api/guides/migration#list_spreadsheets_for_the_authenticated_user

0

For that, you have to use Drives API.

from apiclient import discovery

credentials = get_credential_service_account()
service = discovery.build('drive', 'v3', credentials=credentials)
service.drive().list()

For obtaining "credentials", you can use this code.

Google's official doc is here: https://developers.google.com/drive/v3/reference/changes/list

kmonsoor
  • 7,600
  • 7
  • 41
  • 55
0

Java Implementation :

String url="https://www.googleapis.com/drive/v3/filesq=mimeType='application/vnd.google-apps.spreadsheet'";

public String getSheets(String url) throws UnsupportedEncodingException {

   RestTemplate restTemplate = new RestTemplate();
      HttpHeaders headers = new HttpHeaders();
      headers.add("Authorization", "Bearer " + "Access Token"); 
      HttpEntity entity = new HttpEntity(headers);
      HttpEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
      return response.getBody();
}

Access token can be generated by using below link OAUth Plyaground

Valor_
  • 3,461
  • 9
  • 60
  • 109
user3514641
  • 87
  • 2
  • 12