未找到方法:“虚空Google.Apis.Util.Store.FileDataStore..ctor(System.String)” [英] Method not found: 'Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)'
问题描述
我已经被困在这几天了。我复制了确切的codeS从谷歌API的样本将文件上传到谷歌驱动器。这里是code
I've been stuck at this for days now. I copied the exact codes from google api samples to upload files to Google Drive. Here is the code
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = ClientId,
ClientSecret = ClientSecret,
},
new[] { DriveService.Scope.Drive,
DriveService.Scope.DriveFile },
"user",
CancellationToken.None,
new FileDataStore("MyStore")).Result;
但它会抛出一个异常,在运行时:找不到方法:虚空Google.Apis.Util.Store.FileDataStore..ctor(System.String)。我已经添加了必要的谷歌阿比的DLL。
But it would throw an exception at runtime: Method not found: 'Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)'. I already added the necessary Google Api dlls.
或者,如果任何人都可以提出一个更好的code对于一个网站,实现了服务器端的授权文件上传到谷歌驱动器。任何帮助将大大AP preciated。
Or if anyone could suggest a better code for uploading files to Google Drive in a website which implements Server-Side Authorization. Any help would be greatly appreciated.
更新:我改变了我的code本
UPDATE: I changed my code to this
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);
但它也抛出一个异常:未找到方法:虚空Google.Apis.Auth.OAuth2.Flows.GoogleAuthorization codeFlow..ctor(初始化器)。是问题的dll文件?
But it also throws an exception: Method not found: 'Void Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow..ctor(Initializer). Is the problem with the dlls?
推荐答案
这是我做了什么来解决这个问题:
This is what I've done to resolve the issue :
public UserCredential GetRefreshToken(string refreshToken, string clientID, string clientSecret, string[] scopes)
{
TokenResponse token = new TokenResponse
{
RefreshToken = refreshToken
};
IAuthorizationCodeFlow flow = new AuthorizationCodeFlow(new AuthorizationCodeFlow.Initializer(Google.Apis.Auth.OAuth2.GoogleAuthConsts.AuthorizationUrl, Google.Apis.Auth.OAuth2.GoogleAuthConsts.TokenUrl)
{
ClientSecrets = new ClientSecrets
{
ClientId = clientID,
ClientSecret = clientSecret
},
Scopes = scopes
});
UserCredential credential = new UserCredential(flow, "me", token);
try
{
bool success = credential.RefreshTokenAsync(CancellationToken.None).Result;
}
catch
{
throw;
}
return credential;
}
这篇关于未找到方法:“虚空Google.Apis.Util.Store.FileDataStore..ctor(System.String)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!