C# 第一个Google Drive应用程序使用.NET错误
我在这段代码中有错误。。 我从中获取了相同的代码C# 第一个Google Drive应用程序使用.NET错误,c#,google-drive-api,C#,Google Drive Api,我在这段代码中有错误。。 我从中获取了相同的代码 使用系统; 使用系统诊断; 使用DotNetOpenAuth.OAuth2; 使用Google.api.Authentication.OAuth2; 使用Google.api.Authentication.OAuth2.DotNetOpenAuth; 使用Google.api.Drive.v2; 使用Google.api.Drive.v2.Data; 使用Google.api.Util; 名称空间GoogleDriveSamples { 类Dr
使用系统;
使用系统诊断;
使用DotNetOpenAuth.OAuth2;
使用Google.api.Authentication.OAuth2;
使用Google.api.Authentication.OAuth2.DotNetOpenAuth;
使用Google.api.Drive.v2;
使用Google.api.Drive.v2.Data;
使用Google.api.Util;
名称空间GoogleDriveSamples
{
类DriveCommandLineSample
{
静态void Main(字符串[]参数)
{
String CLIENT\u ID=“您的\u CLIENT\u ID”;
String CLIENT\u SECRET=“您的\u CLIENT\u SECRET”`
//注册验证器并创建服务
var provider=新的本地应用程序客户端(GoogleAuthenticationServer.Description,CLIENT\u ID,CLIENT\u SECRET);
var auth=新的OAuth2Authenticator(提供者,GetAuthorization);
var服务=新的驱动器服务(认证);
文件体=新文件();
body.Title=“我的文档”;
body.Description=“测试文档”;
body.MimeType=“text/plain”;
byte[]byteArray=System.IO.File.ReadAllBytes(“document.txt”);
System.IO.MemoryStream stream=新的System.IO.MemoryStream(byteArray);
fileResource.InsertMediaUpload请求=service.Files.Insert(正文、流、“文本/普通”);
request.Upload();
File File=request.ResponseBody;
Console.WriteLine(“文件id:+File.id”);
WriteLine(“按Enter键结束此过程”);
Console.ReadLine();
}
私有静态IAAuthorizationState GetAuthorization(NativeApplicationClient参数)
{
//获取身份验证URL:
IAAuthorizationState=新授权状态(新[]{DriveService.Scopes.Drive.GetStringValue()});
state.Callback=新Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri=arg.RequestUserAuthorization(状态);
//请求用户授权(通过打开浏览器窗口):
Process.Start(authUri.ToString());
控制台。写入(“授权代码:”);
字符串authCode=Console.ReadLine();
Console.WriteLine();
//使用授权代码检索访问令牌:
返回参数ProcessUserAuthorization(authCode,state);
}
}
}
错误是:
的最佳重载方法匹配
Google.api.Drive.v2.DriveService.DriveService(Google.api.Services.BaseClientService.Initializer)
有一些无效的参数
参数1:无法从转换
Google.api.Authentication.OAuth2.OAuth2Authenticator
转到Google.api.Services.BaseClientService。
以下方法或属性之间的调用不明确:
Google.api.Util.Utilities.GetStringValue(System.Enum)和
Google.api.Util.Utilities.GetStringValue(System.Enum)
我还在项目中引用了所需的Dll。最近更新了.NET客户端库,请检查您的问题的解决方案。缩小您的问题范围。这不是一个“调试我的应用”论坛。var service=newdriveservice(auth);这是我的错误再次从第一步开始。“CLIENT\u ID,CLIENT\u SECRET”是错误的,这两个参数应该是您的值。。。这是我知道的…耶,但是错误会来的。。。我已经提到了粘贴箱上的错误link@HiralBhimani省略过多的“plz”,并包括您在问题中遇到的错误(问题必须是独立的,没有指向某些外部网站的链接,非必要的参考链接除外)。在格式化方面多做一些工作…嘿…grt yaar…thnxxx很多它对我来说非常适合。。。非常感谢你,谢谢你。。。
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<NativeApplicationClient>(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);
}
}
}
The best overloaded method match for
Google.Apis.Drive.v2.DriveService.DriveService(Google.Apis.Services.BaseClientService.Initializer)
has some invalid arguments
Argument 1: cannot convert from
Google.Apis.Authentication.OAuth2.OAuth2Authenticator<Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient>
to Google.Apis.Services.BaseClientService.
The call is ambiguous between the following methods or properties:
Google.Apis.Util.Utilities.GetStringValue(System.Enum) and
Google.Apis.Util.Utilities.GetStringValue(System.Enum)