Tag: 谷歌驱动 SDK

invalid_grant使用服务帐户和Google Drive API返回

我花了两天时间使用服务帐户搞乱各种Drive API教程。 我使用的最新教程是这一个: https : //developers.google.com/drive/delegation 尝试上传文件时,我不断收到此错误消息: ProtocolException was unhandled Error occurred while sending a direct message or getting the response. 我安装了Fiddler并确定当POST /o/oauth2/token返回时: { “error:”invalid_grant” } 我已经三次+检查了我的申请范围。 我究竟做错了什么?

使用Google Drive API v3移动文件

我正在尝试使用Google Drive API v3将文件从一个文件夹移动到另一个文件夹。 我在这里找到了文档。 我使用了文档页面中的.NET示例代码,并创建了一个如下所示的方法: public ActionResult MoveFile(string fileToMove, string destination) { DriveService service = new DriveService(new BaseClientService.Initializer { HttpClientInitializer = , ApplicationName = “APPNAME” }); var searchFiles = service.Files.List(); searchFiles.Corpus = FilesResource.ListRequest.CorpusEnum.User; searchFiles.Q = “name = ‘” + fileToMove + “‘”; searchFiles.Fields = “files(*)”; string fileToMoveId = searchFiles.Execute().Files[0].Id; searchFiles.Q = “name = ‘” […]

更改Google云端硬盘中的重定向url – C#(第2部分)

我不知道为什么,但这个消息被主持人在我的第一个问题中删除,主持人写道我需要打开新问题。 所以……(第1部分 – 更改Google默认的Auth重定向 – C#(Google liblary) ) 我尝试不好有问题:如果我尝试这个代码: public class MyNewAuthorizationCodeMvcApp : AuthorizationCodeMvcApp { public MyNewAuthorizationCodeMvcApp(Controller controller, FlowMetadata flowData) : base(flowData.Flow, “http://www.yandex.ru”, controller.Request.Url.ToString()) { } } 我得到的错误是:AuthorizationCodeMvcApp构造函数(默认liblary)不会对带有3个参数的构造函数进行竞争 如果我尝试: public class MyNewAuthorizationCodeMvcApp : AuthorizationCodeWebApp { public MyNewAuthorizationCodeMvcApp(Controller controller, FlowMetadata flowData) : base(flowData.Flow, “http://www.yandex.ru”, controller.Request.Url.ToString()) { } } 我没有得到错误但是! 我不能设置Valeu this.controller = controller; this.flowData = flowData; […]

Google驱动示例:未找到oauth2callback

我需要对Google-Drive的C#示例程序有所帮​​助…… 我使用了这个所谓的 “教程”/“例子”: https://developers.google.com/drive/examples/dotnet 而这里的代码: https://code.google.com/p/google-drive-sdk-samples/source/checkout 我在这里上传了我的(仅略微修改过的)源代码,以防任何人没有Mercurial(我没有Mercurial,也没有管理员权限来安装它,Mercurial是获取源代码的唯一方法……): http://verzend.be/elt0k13enraw/DrEdit.rar.html 我总是得到 “无法找到资源” 请求的URL:/ oauth2callback 我没有发现这令人惊讶,因为没有实现oauth2callback控制器或处理程序… 我尝试添加一个名为oauth2callbackController的Controller,并重定向到oauth2callbackController.Index中的另一个动作, return new RedirectResult(“/about/about”); 但是这只会创建一个NULL引用exception。 所以我想,可能是错误的控制器并重定向到 return new RedirectResult(“/drive/Index”); 但这只会创建一个无限循环的重定向 – >允许 – >重定向 – 允许 – >等。 顺便说一句,更改API密钥+ REDIRECT_URI的配置在 Models\ClientCredentials.cs 注意: 问题不是我的修改。 样本也没有修改,没有完全相同的错误。 我所做的只是删除EntityFramwork引用,并在调用使用实体的方法时抛出“未实现的exception”。 编辑: 附加信息: 我真正想要做的是编写一个导出我的数据库的控制台服务,LZMA压缩导出的内容,使用OpenPGP加密,并在24:00每天将我的服务器数据库上传到Google驱动器’时钟,没有任何用户输入。 我的导出工作没有问题,我得到LZMA压缩工作没有问题,我得到加密与PGP工作没有问题。 在工作日结束后(grrrr),当我在家时,我甚至可以在家里的Linux机器上安装mercurial下载示例代码,并使用SMB将其带到Windows机器上。 。 但现在我无法获得Google-drive SDK的样本… 而且,我真正需要的是控制台服务/守护进程的示例,而不是Web应用程序。 当我创建API密钥时,我看到可以为服务创建密钥,但是没有关于如何编写Google-Drive服务(控制台应用程序)的示例,也没有有用的文档(是的,有参考,但它只是一个参考,IntelliSense提供的相同)…

使用.net sdk检索google驱动器文件列表

我正在尝试从Google云端硬盘中获取文件列表,我正在使用它们提供的示例: public static List RetrieveAllFiles(DriveService service) { List result = new List(); FilesResource.ListRequest request = service.Files.List(); do { try { FileList files = request.Fetch(); result.AddRange(files.Items); request.PageToken = files.NextPageToken; } catch (Exception e) { Console.WriteLine(“An error occurred: ” + e.Message); request.PageToken = null; } } while (!String.IsNullOrEmpty(request.PageToken)); return result; } 它总是返回文件count = 0而我很确定登录帐户有很多文件! 还有其他需要吗? 编辑:用于身份validation: public […]

如何获取Google文档的说明?

目标 假设我在Google文档/云端硬盘中有一个文档集/文件夹,我想以编程方式检索与每个文档关联的说明: (您可以通过选择列表中的文件,然后点击“眼睛”图标来获得此信息) 工作守则 我正在将.NET库用于Google Data API,并且基本的登录和检索工作没有问题: GDataCredentials credentials = BuildSomethingUp(); RequestSettings settings = new RequestSettings(“code.google.com/p/exult/”, credentials); Request request = new Request(settings); Feed feed = request.GetFolderContent(resourceId); List documents = feed.Entries.ToList(); foreach (Document document in documents .Where(item => item.Type != Document.DocumentType.Folder)) { string summary = document.Summary; //y no can haz? } 但是, .Summary属性始终返回null。 问题 我正在假设.Summary是基于一些不推荐的代码部分等的正确位置。这是一个虚假的假设吗? 我怎样才能检索与文档相关的描述? […]

找不到方法:’Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)’

我已经被困在这几天了。 我复制了google api示例中的确切代码,以便将文件上传到Google云端硬盘。 这是代码 UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = ClientId, ClientSecret = ClientSecret, }, new[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile }, “user”, CancellationToken.None, new FileDataStore(“MyStore”)).Result; 但它会在运行时抛出一个exception:找不到方法:’Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)’。 我已经添加了必要的Google Api dll。 或者,如果有人可以在实施服务器端授权的网站上建议更好的代码将文件上传到Google云端硬盘。 任何帮助将不胜感激。 更新:我将我的代码更改为此 var token = new TokenResponse { RefreshToken = “1/6hnki1x0xOMU4tr5YXNsLgutzbTcRK1M-QOTEuRVxL4” }; var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = […]

Google Drive API – 从服务帐户转移所有权

我正在尝试将所有权从服务帐户创建的文档转移到使用以下代码驻留在同一Google Apps帐户中的其他用户,但我收到以下错误 资源主体包括不可直接写入的字段。 [403]错误[消息[资源主体包括不可直接写入的字段。]位置[ – ]原因[fieldNotWritable]域[全局]] var service = GetService(); try { var permission = GetPermission(fileId, email); permission.Role = “owner”; var updatePermission = service.Permissions.Update(permission, fileId, permission.Id); updatePermission.TransferOwnership = true; return updatePermission.Execute(); } catch (Exception e) { Console.WriteLine(“An error occurred: ” + e.Message); } return null; 评论//权限.Role =“所有者”; 返回以下错误 当权限角色为“所有者”时,必须启用transferOwnership参数。 [403]错误[消息[当权限角色为’所有者’时,必须启用transferOwnership参数。)位置[transferOwnership – 参数]原因[禁止]域[全局]] 分配任何其他权限工作正常。 因此,这是服务帐户的限制,无法将所有权转移到不使用@ gserviceaccount.com电子邮件地址的任何其他帐户(即our-project@appspot.gserviceaccount.com> […]

C#google驱动器服务帐户下载问题

我创建了服务帐户,我向这个帐户公开了几个文件,一旦我想下载文件,就会抛出exception Google.Apis.Requests.RequestError错误请求[400]错误[消息[错误请求]位置[ – ]原因[badRequest]域[全局]] var certificate = new X509Certificate2(“*******.p12”, “notasecret”, X509KeyStorageFlags.Exportable); try { ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(“*******..com”) { Scopes = scopes }.FromCertificate(certificate)); // Create the service. DriveService service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = “Daimto Drive API Sample”, }); var files = service.Files.List().Execute().Files; var request = service.Files.Get(files.First().Id); var […]

Google云端硬盘。 上传文件时刷新授权令牌

在将大文件上传到Google云端硬盘时刷新授权令牌的方法是什么? 例如:当前授权令牌的到期时间是“06:00 AM”。 文件上传始于“05:15 AM”。 因此,在“06:00 AM”,应用程序获得exception,因为授权令牌无效。 我已尝试使用以下源代码来解决此问题,但它无法正常工作。 /// /// Uploads a file with a specified path. /// /// The start folder. /// The path of destination file. /// The local file to upload. /// The uploaded file. private File GdUploadFile(File startFolder, string path, FileInfo localFile) { if (startFolder == null) { throw new ArgumentNullException(“startFolder”); […]