我正在开发 Web 应用程序以使用 C# 在 ASP.NET 中的 Google Drive 上上传文件。
在运行应用程序时,我想使用自动身份验证技术将文件自动上传到 Google Drive。以下是用于上传文件但无法通过 Google API 进行身份验证的类文件。GetAuthorization() 有问题。请帮助我...
namespace Cloud { class Code { private static readonly string CLIENT_ID = "303453771054- 4ftp53uun2o6jeiii85i22muc4fio76f.apps.googleusercontent.com"; private static readonly string CLIENT_SECRET = "wMc6mptgMTOL1ncGSJX-qoPS"; private static readonly string APIKEY = "AIzaSyAVyZF8OVl4Vvrbu9pWUQCzx35afdpYJR0"; private static readonly string REDIRECTURI = "http://localhost:49632/CloudCode.aspx"; private static readonly string[] SCOPES = new[] { DriveService.Scopes.Drive.GetStringValue() }; public void Main(string Filename) { var provider = new WebServerClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET); provider.ClientIdentifier = CLIENT_ID; provider.ClientSecret = CLIENT_SECRET; provider.RequestUserAuthorization(); provider.ProcessUserAuthorization(null); var authenticator = new OAuth2Authenticator<WebServerClient>(provider, GetAuthorization); File body = new File(); body.Title = "My document"; body.Description = "A test document"; body.MimeType = "text/plain"; body.OriginalFilename = Filename; byte[] byteArray = System.IO.File.ReadAllBytes(body.OriginalFilename.ToString()); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); DriveService service = new DriveService(); FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain"); request.Upload(); File file = request.ResponseBody; } private IAuthorizationState GetAuthorization(WebServerClient arg) { IAuthorizationState state = arg.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request)); IAuthorizationState AuthorizationState=new AuthorizationState(SCOPES); AuthorizationState.Callback = new Uri(REDIRECTURI); return AuthorizationState; }