31

When running the Java quickstart sample at https://developers.google.com/drive/web/quickstart/java?hl=hu in NetBeans, I'm receiving the error code:

Jun 04, 2015 12:12:11 AM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody:
C:\Users\Quibbles\credentials\drive-api-quickstart

What am I doing wrong?

Edit: This is the complete error message.

Jun 04, 2015 5:11:39 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\Quibbles\.credentials\drive-api-quickstart
Exception in thread "main" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:78)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
    at DriveQuickstart.authorize(DriveQuickstart.java:64)
    at DriveQuickstart.getDriveService(DriveQuickstart.java:87)
    at DriveQuickstart.main(DriveQuickstart.java:96)
Java Result: 1
quibblify
  • 395
  • 2
  • 6
  • 13

8 Answers8

35

Had the same issue and wasted hours before realizing that "unable to change permissions for owner: C:\Users\Quibbles.credentials\drive-api-quickstart"
is just a warning.

The real issue is the null pointer here.

InputStream in =
            DriveQuickstart.class.getResourceAsStream("/client_secret.json");

This line was the issue in my case. "in" was null and hence the null pointer.

InputStream in    = new FileInputStream("<Full Path>\\client_secret.json");  

This resolved my issue.

C Deepak
  • 1,258
  • 1
  • 17
  • 23
  • 1
    Had the same issue in "google-api-java-client-samples-master". Here you should do `InputStreamReader in = new InputStreamReader(new FileInputStream("\\client_secrets.json"));` Because `GoogleClientSecrets.load` only does not accept a `InputStream`. – Maiko Kingma Oct 10 '17 at 08:32
17

The actual problem is a bug in Google's API code for setPermissionsToOwnerOnly

The code was written to only work on Linux/Unix based systems and not Windows ACL based systems.

You can ignore the warning or write your own DataStore class that sets the permissions correctly for Windows.

I'm going to try to file a bug with Google on it too.

JustADev
  • 171
  • 1
  • 2
  • 2
    Source problem is at this GitHub repo owned by Google. Code hasn't been updated since 2013. https://github.com/google/google-http-java-client/blob/dev/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java – JustADev Jan 16 '16 at 03:58
  • 2
    I've submitted a bug issue report to Google: https://github.com/google/google-http-java-client/issues/315 – JustADev Jan 16 '16 at 04:02
  • 8
    To disable the WARNING message caused by the Google library code bug use: final java.util.logging.Logger buggyLogger = java.util.logging.Logger.getLogger(FileDataStoreFactory.class.getName()); buggyLogger.setLevel(java.util.logging.Level.SEVERE); – JustADev Jan 17 '16 at 04:16
5

I was facing same issue in Eclipse. Here’s a solution:

  1. Run eclipse in admin mode

  2. Clear the directory C:/Users/<username>.credentials/calendar-java-quickstart.json

  3. Copy the .json file the bin directory, e.g. bin/main/resources/client_secret.json

You are free to run now.

dakab
  • 5,379
  • 9
  • 43
  • 67
Dilip Mane
  • 51
  • 1
  • 1
3

Basically if you already enabled de Drive API and created credentials.json file at Google Drive API Rest, now you need :

1 - Remove the tokens directory generated in you last execution. In this directory contains a file StoredCredential. 2 - Change de SCOPE to DriveScopes.DRIVE like sample bellow:

private static List SCOPES = Collections.singletonList(DriveScopes.DRIVE);

3 - Re run the program. It will be request that you login in your google account to give the access consent.

4 - It will be generated a new one tokens directory in your project and now with with read and write permissions at google Drive.

This work for me.

0

I just ran into the same issue with the https://developers.google.com/google-apps/calendar/quickstart/java example. I suspect that the issue is that you are running it in Windows and the JVM that you are running it does not have Adminsitrator rights for changing the file permissions in Windows.

See Run Java application as administrator on Windows

Community
  • 1
  • 1
nicordesigns
  • 904
  • 1
  • 9
  • 18
0

Had the same problem when running the example given in the tutorial "https://developers.google.com/drive/v2/web/quickstart/java". Followed the instruction ditto as given the in the tutorial, but kept getting this permission exception. Eventually, managed to sort it out by moving the "client_secret.json" to the "\build\classes\main\classes" folder. Also, before building the project with "gradle -q run" for the first time, delete any files in the "C:\Users\userName\.credentials" folder.

0

Just make sure that client_secret.json is under main/resources/ directory.enter image description here

InputStream in =
            DriveQuickstart.class.getResourceAsStream("/json/client_secret.json");
0

Was able to resolve the issue by deleting the StoredCredentials files under the token folder. I had to reauthenticate again with google the next time the program was executed.

AshX
  • 1