java 警告:无法更改每个人的权限:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30634827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:25:05  来源:igfitidea点击:

WARNING: unable to change permissions for everybody:

javagoogle-drive-api

提问by quibblify

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

在 NetBeans中的https://developers.google.com/drive/web/quickstart/java?hl=hu 上运行 Java 快速入门示例时,我收到错误代码:

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

回答by C Deepak

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.

在意识到“无法更改所有者的权限:C:\Users\Quibbles.credentials\drive-api-quickstart”之前遇到了同样的问题并浪费了几个小时
只是一个警告。

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.

这条线是我的问题。“in”为空,因此为空指针。

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

This resolved my issue.

这解决了我的问题。

回答by JustADev

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

实际问题是 Google 的 setPermissionsToOwnerOnly API 代码中的一个错误

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

该代码仅适用于基于 Linux/Unix 的系统,而不适用于基于 Windows ACL 的系统。

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

您可以忽略警告或编写自己的 DataStore 类来为 Windows 正确设置权限。

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

我也将尝试向 Google 提交错误。

回答by Dilip Mane

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

我在 Eclipse 中遇到了同样的问题。这是一个解决方案:

  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

  1. 在管理模式下运行 eclipse

  2. 清除目录 C:/Users/<username>.credentials/calendar-java-quickstart.json

  3. 将 .json 文件复制到 bin 目录,例如 bin/main/resources/client_secret.json

You are free to run now.

你现在可以自由奔跑了。

回答by Eduardo Aparecido

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

基本上,如果您已经启用了 de Drive API 并在Google Drive API Rest创建了 credentials.json 文件,现在您需要:

1 - Remove the tokensdirectory generated in you last execution. In this directory contains a file StoredCredential. 2 - Change de SCOPEto DriveScopes.DRIVElike sample bellow:

1 - 删除上次执行时生成的令牌目录。在这个目录中包含一个文件 StoredCredential。2 -像下面的示例一样将de SCOPE更改为DriveScopes.DRIVE

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

私有静态列表范围 = 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.

3 - 重新运行程序。它将要求您登录您的谷歌帐户以授予访问许可。

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

4 - 它将在您的项目中生成一个新的令牌目录,现在在 google Drive 具有读写权限。

This work for me.

这对我有用。

回答by AshX

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.

能够通过删除令牌文件夹下的 StoredCredentials 文件来解决该问题。下次执行程序时,我不得不再次使用谷歌重新进行身份验证。

回答by nicordesigns

I just ran into the same issue with the https://developers.google.com/google-apps/calendar/quickstart/javaexample. 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.

我刚刚在https://developers.google.com/google-apps/calendar/quickstart/java示例中遇到了同样的问题。我怀疑问题是您在 Windows 中运行它,而您运行它的 JVM 没有在 Windows 中更改文件权限的管理员权限。

See Run Java application as administrator on Windows

请参阅在 Windows 上以管理员身份运行 Java 应用程序

回答by user1864863

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.

运行教程“ https://developers.google.com/drive/v2/web/quickstart/java”中给出的示例时遇到了同样的问题。按照教程中给出的说明同上,但不断获得此权限异常。最终,通过将“client_secret.json”移动到“\build\classes\main\classes”文件夹来设法解决它。此外,在首次使用“gradle -q run”构建项目之前,请删除“C:\Users\userName\.credentials”文件夹中的所有文件。

回答by Николай Беляков

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

只需确保 client_secret.json 位于 main/resources/ 目录下。在此处输入图片说明

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