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