我正在使用C#开发Web应用程序以在ASP.NET上的Google云端硬盘上传文件。
在运行应用程序时,我想使用自动身份验证技术自动将文件上传到Google云端硬盘。 以下是用于上传文件但无法向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; }