缺少 TClient 参数

问题描述 投票:0回答:1

我正在关注 google QuickStart google Drive .NET api 视频,此时出现错误。我按照他们所说的一切进行操作,添加了所有必需的 dll。我在虚拟机上运行 Windows 7,使用 Visual Studio 2012,这可能是问题所在吗?

复制粘贴他们的代码后,我无法构建它。 我收到此错误:

OAuth2.OAuth2Authenticator' 需要 1 个类型参数

我在 Google 上找不到有关此错误的任何信息,也找不到有关 TClient 的信息

我缺少的 TClient 参数是什么?

代码

using System;
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Util;

namespace GoogleDriveSamples
{
    class DriveCommandLineSample
    {
        static void Main(string[] args)
        {
            String CLIENT_ID = "YOUR_CLIENT_ID";
            String CLIENT_SECRET = "YOUR_CLIENT_SECRET";

            // Register the authenticator and create the service
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
            var auth = new OAuth2Authenticator(provider, GetAuthorization);
            var service = new DriveService(auth);

            File body = new File();
            body.Title = "My document";
            body.Description = "A test document";
            body.MimeType = "text/plain";

            byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

            FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
            request.Upload();

            File file = request.ResponseBody;
            Console.WriteLine("File id: " + file.Id);
            Console.WriteLine("Press Enter to end this process.");
            Console.ReadLine();
        }

        private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
        {
            // Get the auth URL:
            IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
            Uri authUri = arg.RequestUserAuthorization(state);

            // Request authorization from the user (by opening a browser window):
            Process.Start(authUri.ToString());
            Console.Write("  Authorization Code: ");
            string authCode = Console.ReadLine();
            Console.WriteLine();

            // Retrieve the access token by using the authorization code:
            return arg.ProcessUserAuthorization(authCode, state);
        }
    }
}
c# .net dll google-drive-api
1个回答
0
投票

您的解决方案中似乎存在设置或配置问题。尝试按照 Google Developers Live 会话视频中的分步说明进行操作,其中介绍了 .NET Drive 快速入门:

http://www.youtube.com/watch?v=uwrJSWqglTc

© www.soinside.com 2019 - 2024. All rights reserved.