Tag: 谷歌驱动 SDK

Google Drive SDK – Java示例无效

我正在尝试使用官方Java示例熟悉Google Drive API。 但是,在浪费了几个小时并尝试将样品放置两次之后,我仍然无法按预期使用它。 它不是显示文件的内容,而是在FileServlet(/ svc路径)中抛出404错误。 更具体地说, service.files().get(fileId).execute(); 似乎返回null。 我已尝试使用不同的文件,不同的MIME类型,直接来自Google云端硬盘以及使用Google文件选择器。 我已尽可能地遵循https://developers.google.com/drive/examples/java中描述的步骤。 有没有人能够让样本运行? 编辑:这是请求URL /svc?file_id=0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw时FileServlet的日志输出/svc?file_id=0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw (在第78行抛出404错误): 2012-04-26 08:21:36.077 com.google.api.client.http.HttpRequest execute: ————– REQUEST ————– GET https://www.googleapis.com/drive/v1/files/0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw Accept-Encoding: gzip User-Agent: Google-HTTP-Java-Client/1.8.3-beta (gzip) D 2012-04-26 08:21:36.263 com.google.api.client.http.HttpResponse : ————– RESPONSE ————– 403 OK content-type: application/json; charset=UTF-8 content-encoding: gzip date: Thu date: 26 Apr 2012 06:21:36 GMT expires: Thu expires: […]

com.google.api.client.json.jackson.JacksonFactory; Google云端硬盘示例中缺少

我尝试运行quickstart-sample ,这个依赖项: com.google.apis google-api-services-drive v2-rev78-1.15.0-rc 来自Drive wiki API页面 然而,当我尝试编译com.google.api.client.json.jackson.JacksonFactory;代码时com.google.api.client.json.jackson.JacksonFactory; 不见了。 要validation这一点,您只需要执行第2步和第3步! 我在哪里可以找到这个类或如何在样本中替换它?

appdata范围内无法更新文件存储 – 500内部服务器错误

以前,我有一套Google Drive API代码,在以下情况下可以正常使用 将新文件保存到appdata 在appdata中更新以前的文件 将新文件保存到非appdata 更新非appdata中的上一个文件 几天前,我遇到方案2不再工作(更新appdata中的上一个文件),而其他方案仍然没有问题。 我将得到以下exception。 com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error { “code”: 500, “errors”: [ { “domain”: “global”, “message”: “Internal Error”, “reason”: “internalError” } ], “message”: “Internal Error” } at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145) at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113) at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460) at org.yccheok.jstock.gui.Utils.updateFile(Utils.java:1414) 我正在使用DRIVE和DRIVE_APPDATA范围 – authorizeDrive() 代码如下 saveToGoogleDrive() – 在appdata中保存或更新文件, 在更新文件期间不起作用 […]

如何使用drive api java从谷歌驱动器下载文件?

我尝试了一些谷歌硬盘的function,但我无法从云端硬盘下载该文件。 这是我使用的代码 private static InputStream downloadFile(Drive service, File file) { if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) { try { HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())) .execute(); return resp.getContent(); } catch (IOException e) { // An error occurred. e.printStackTrace(); return null; } } else { // The file doesn’t have any content stored on Drive. […]

Google Drive SDK API未列出Google Drive在Google中上传的文件

我正在创建一个可以将文件插入Google云端硬盘并列出的应用程序。 我使用的是Google Drive SDK v2 API。 但我的问题是它没有列出未通过我的应用程序上传的文件。 如果我直接从Google云端硬盘上传,则不会在我的应用中列出。 以下是列出文件的方法: private static List retrieveAllFiles(Drive service) throws IOException { List result = new ArrayList(); Files.List request = service.files().list(); do { try { FileList files = request.execute(); result.addAll(files.getItems()); request.setPageToken(files.getNextPageToken()); } catch (IOException e) { System.out.println(“An error occurred: ” + e); request.setPageToken(null); } } while (request.getPageToken() != null && […]

Google云端硬盘服务帐户返回403 usageLimits

我正在尝试编写一个AppEngine应用程序,将Google文档写入Google云端硬盘,放入一组特定的文件夹并设置访问权限。 我使用旧的DocsList API,但由于刚刚被弃用,我决定更新我的代码(我还有一些额外的function可以添加)。 我面临的问题是:当我使用服务帐户并尝试冒充特定用户时,即使我没有用完任何配额,我也会获得带有usageLimits的403。 这是我正在使用的代码: GoogleCredential credentials = new GoogleCredential.Builder() .setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(“xxxxxxxxxxgserviceaccount.com”) .setServiceAccountScopes(DriveScopes.DRIVE) .setServiceAccountPrivateKeyFromP12File( new java.io.File(“xxxx-privatekey.p12”)) .setServiceAccountUser(“user@xxxxxx.org”).build(); 我使用这些凭据来启动我的Drive对象: Drive d = Drive.builder(httpTransport, jsonFactory) .setHttpRequestInitializer(credentials) .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() { @Override public void initialize(JsonHttpRequest request) { DriveRequest driveRequest = (DriveRequest) request; driveRequest.setPrettyPrint(true); } }).setApplicationName(“MYAPPNAME”).build(); 顺便说一句:我尝试过使用新的Drive(….),但无论我尝试什么,这都行不通。 保持抛出错误,找不到内部方法! 回到这个问题:当我使用’d’来调用类似.files()的东西.get(“SOMEFILEID”)。execute()我得到403 { “code” : 403, “errors” : [ { “domain” : […]

exceptionjava.lang.NoClassDefFoundError:com.google.android.gms.common.AccountPicker

我正在尝试快速入门:从Android Drive SDK 在Android上运行云端硬盘应用 。 我已经遵循了这个过程,但是当我在我的设备中运行应用程序(真实的应用程序)时,它会崩溃并出现以下exception: java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker 最后,它在此代码的第二行指向我的源代码: credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE); startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER); // <- This one 我的讨论来自于我完成了文章指示我做的所有事情: 我已经生成了证书 启用API(带证书指纹) 在Eclipse中创建并配置了android项目 添加了Google插件的API 复制样本(我实际上做了复制粘贴) 当然,我更正了包和类名 此外,我还添加了应用程序的权限,甚至还有其他权限 我甚至添加了Google Play Android Developer API及其perimssions。 但是当我运行App时,它仍然会崩溃。 所有的图书馆似乎都很好。 我想知道它是否特定于Android APIv17,因为我的设备是APIv10和APIv15(我也添加了支持库)。 请帮忙。 请原谅我的英语不好。 谢谢。

com.google.api.client.googleapis.json.GoogleJsonResponseException:403 Forbidden

我正在尝试将文本文件上传到我的Google云端硬盘帐户。 无论如何,我总是遇到com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden 堆栈跟踪: Exception in thread “main” com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden { “code” : 403, “errors” : [ { “domain” : “global”, “message” : “Forbidden”, “reason” : “forbidden” } ], “message” : “Forbidden” } at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145) at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113) at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460) at chatterjee.sandeep.javabase.miscellaneous.DriveCommandLine.main(DriveCommandLine.java:69) 这是DriveCommandLine.java第69行 File file = service.files().insert(body, mediaContent).execute(); […]

使用Google Drive SDK将文件保存在特定文件夹中

我一直在尝试将纯文本文件保存到Android上的Google云端硬盘中的特定文件夹中。 到目前为止,使用Google云端硬盘上的文档和快速入门指南 ,我已经能够做一些正确的方向,首先我能够创建纯文本文件: File body = new File(); body.setTitle(fileContent.getName()); body.setMimeType(“text/plain”); File file = service.files().insert(body, textContent).execute(); 我已经能够在Google云端硬盘的基本目录中创建一个新文件夹: File body = new File(); body.setTitle(“Air Note”); body.setMimeType(“application/vnd.google-apps.folder”); File file = service.files().insert(body).execute(); 我还能够列出用户的Google云端硬盘帐户中的所有文件夹: List files = service.files().list().setQ(“mimeType = ‘application/vnd.google-apps.folder'”).execute().getItems(); for (File f : files) { System.out.println(f.getTitle() + “, ” + f.getMimeType()); } 但是我对如何将文本文件保存到Google云端硬盘中的文件夹感到困惑。

OAuth Google API for Java无法冒充用户

我想模仿用户并代表他们从服务器进程向用户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 […]