Method not found: 'Void Google.Apis.Util.Store.FileDataStore..ctor (System.String)'

I’ve been stuck with this for several days. 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;

But it will throw an exception at runtime: Method not found: "Void Google.Apis.Util.Store.FileDataStore..ctor (System.String)". I have already added the necessary Google Api DLLs.

Or, if someone can offer the best code to upload files to Google Drive on a website that implements server-side authorization. Any help would be greatly appreciated.

UPDATE: I changed the 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);

But it also throws an exception: Method not found: "Void Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow..ctor (Initializer). Is there a problem with the dll?

+4
4

, v1.8.2 of Google APIs Client Library. v1.8.1 nuget .NET framework 4.

+1

. (1.8.2), . , VS2010 .NET 4? (, .NET Framework 4.0 KB2468871 (http://www.microsoft.com/en-us/download/details.aspx?id=3556).

, , , . VS 2012 Windows 8. ?

(https://code.google.com/p/google-api-dotnet-client/issues/list), .

+1

:

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;
}
+1

Visual Studio 2013 + Update 3 win 8.1 .NET 4.5 ( ). google-apis. ".NET Framework 4" ( , → → "" → " " ) apis nuget :

PM> Install-Package Google.Apis
PM> Install-Package Google.Apis.Auth
PM> Install-Package Google.Apis.Drive.v2
0

Source: https://habr.com/ru/post/1544248/


All Articles