突然,今天我的服务尝试通过Drive API将文件插入Google驱动器的请求开始收到400错误.该错误表示需要注册的应用程序,完整错误如下.应用程序已在我的Google Cloud控制台中注册,但应用程序名称与我的服务使用的应用程序名称不匹配.我重命名了服务应用程序名称,但错误仍在继续.
400 Bad Request
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "Registered app required, either through authentication token or key param.",
"reason": "required"
}
],
"message": "Registered app required, either through authentication token or key param."
}
Run Code Online (Sandbox Code Playgroud)
是否还需要设置其他内容,或者这可能会延迟重命名服务?
编辑:我能够列出,更新和下载文件,但我无法插入.
我想模仿用户并代表他们从服务器进程向用户Google Drive添加文件.我已经设置了一个服务帐户,可以使用以下代码成功访问驱动器作为服务帐户添加和列出文件等:
/** Global instance of the HTTP transport. */
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
public static void main(String[] args) {
try {
GoogleCredential credential =
new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("XXXXX@developer.gserviceaccount.com")
.setServiceAccountScopes(DriveScopes.DRIVE)
.setServiceAccountPrivateKeyFromP12File(new File("c:/junk/key.p12"))
.build();
Drive drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).build();
drive.files().list().execute();
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
这有效,但只返回与我假设与服务帐户驱动器(?)关联的文件.
根据JavaDoc,GoogleCredential还可以通过添加服务帐户用户电子邮件地址来模拟用户,如下所示:
GoogleCredential credential =
new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("XXXXX@developer.gserviceaccount.com")
.setServiceAccountScopes(DriveScopes.DRIVE)
.setServiceAccountPrivateKeyFromP12File(new File("c:/junk/key.p12")) …Run Code Online (Sandbox Code Playgroud) 在负载测试期间测试Tomcat NIO连接器时,我们想到了这一点.我使用ThreadLocal另外我使用Spring,我知道在几个地方它也使用它.
由于NIO连接器每个连接没有一个线程,我担心如果ThreadLocal对象在清理之前与另一个线程共享,则可能导致很难找到错误.但是,我认为这不是一个问题,因为它不是我能找到的文件警告,也没有发现任何其他帖子警告这一点.我假设NIO连接器对服务于实际请求的线程没有影响.
在我采用这个假设之前,我希望找到一些具体的证据.
我的应用程序要求一部分用户能够编辑与他们共享并归其他人所有的 Google 文档,但是文档访问权限不应由这些用户管理,他们应该只有编辑访问权限。
似乎默认设置是编辑者可以管理共享文件访问,但可以通过在 UI 中将文件共享设置显式设置为“只有所有者可以更改权限”来防止这种情况。
问题是我正在使用 Google Drive SDK 管理这些文件,但我看不到任何通过 SDK 更改此设置的方法。这可能吗?