mercredi 22 avril 2015

Java get metadata of public file on Google Drive

Hello I've downloaded and installed the latest version of Drive REST API for java and want to get the metadata of a public file from Google Drive by the fileID - I have the following code:

private static final String APPLICATION_NAME = "test";
private static final String FILE_ID = "theFileId";


public static void main(String[] args) {

    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();

    Drive service = new Drive.Builder(httpTransport, jsonFactory, null).setApplicationName(APPLICATION_NAME).build();

    printFile(service, FILE_ID);
}


private static void printFile(Drive service, String fileId) {

  try {
      File file = service.files().get(fileId).execute();
      System.out.println("Title: " + file.getTitle());
  } catch (IOException e) {
      System.out.println("An error occured: " + e);
  }
}

But I get the error message: "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

I've tried it on http://ift.tt/Q3fmNw which worked out just fine.

Do I have to authenticate with an API key when the file is public and how would I do that if so.

Thanks for your time.

Aucun commentaire:

Enregistrer un commentaire