나는이 일 동안 지금 당황했습니다. Google 드라이브에 파일을 업로드하기 위해 Google API 샘플의 정확한 코드를 복사했습니다. 여기에 코드메서드를 찾을 수 없음 : 'Void Google.Apis.Util.Store.FileDataStore..ctor (System.String)'
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)'. 이미 필요한 Google Api DLL을 추가했습니다.
또는 누군가가 서버 측 인증을 구현하는 웹 사이트의 Google 드라이브에 파일을 업로드하는 데 더 좋은 코드를 제안 할 수 있습니다. 어떤 도움이라도 대단히 감사하겠습니다.
UPDATE :이
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.GoogleAuthorizationCodeFlow..ctor (이니셜). dll에 문제가 있습니까?
런타임에이 예외가 발생합니까? 아니면 컴파일 오류가 발생합니까? –
런타임에 throw합니다 – user3732193
왜이 예외가 발생했는지 정확히 알지 못하지만 적어도 다음과 같이 생각해야합니다. UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync (...); 또는 메서드 비동기를 다음과 같이 실행하지 않으려면 var task = GoogleWebAuthorizationBroker.AuthorizeAsync (...); var cred = task.Wait(); 너 시도 할 수있어 ? async를 실행하지 않는 Btw는 앱의 메인 스레드를 차단할 것이므로 좋지 않습니다. – Dragouf