我想使用Google Drive API以及简单的WEB API 2 - Project。 不知何故GoogleWebAuthorizationBroker.cs丢失。Google Drive APi with clean WEB API 2
我用什么: 的Visual Studio 2013更新4 空的模板与WEB API
我的步骤:
- 创建空的项目包括Web API
- 建设项目
- 更新通过Nuget Packager安装包
- 安装包Google.Apis.Drive.v2(使用本指南:https://developers.google.com/drive/web/quickstart/quickstart-cs)
复制并从上面的链接的代码粘贴到一个干净的API控制器:
public IEnumerable<string> Get() { UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = "228492645857-5599mgcfnhrr74a7er1do1chpam4rnbt.apps.googleusercontent.com", ClientSecret = "onoyJQaUazQK4VsKUjD63sDu", }, new[] { DriveService.Scope.Drive }, "user", CancellationToken.None).Result; // Create the service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Drive API Sample", }); File body = new File(); body.Title = "My document"; body.Description = "A test document"; body.MimeType = "text/plain"; byte[] byteArray = System.IO.File.ReadAllBytes(@"C:\Projects\VS\DataAnime\DataAnime\document.txt"); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain"); request.Upload(); File file = request.ResponseBody; return new string[] { file.Id, "value2" }; }
建设
6.1错误:GoogleWebAuthorizationBroker.cs缺少
6.2谷歌说,浏览器中出现以下错误:
That’s an error. Error: redirect_uri_mismatch
Application: Project Default Service Account
You can email the developer of this application at: [email protected]
The redirect URI in the request: http://example.com:63281/authorize/ did not match a registered redirect URI.
http://example.com:63281/authorize/ was neither the url i am using for my project nor the url i registered in my developer console (this errorshowing-port is changeing everytime i run this project.
有没有人知道这是为什么? 没有其他来源帮助解决这个奇怪的问题。
我检查过文件,它说,当你创建谷歌证书时,你必须指定'redirect url',并且重定向url与localhost:port不匹配。 –
我知道,我已经将这个重定向-URI设置为我的项目URL。 如果我调试类如上所述缺少,这就是为什么错误显示我认为。 –
你能告诉我,google凭证设置中的重定向网址是什么? –