C# 无法使用google坐标服务创建作业

C# 无法使用google坐标服务创建作业,c#,google-maps,google-api,google-api-dotnet-client,C#,Google Maps,Google Api,Google Api Dotnet Client,VisualStudio2010 框架4.0 我正在尝试使用谷歌坐标API插入作业。对于插入作业,我尝试了两种方法。使用webrequest和坐标API。但我无法插入作业。 使用Google坐标API:获取错误“名称空间Google.API中不存在身份验证” 我使用nuget安装了google坐标API。我使用下面的代码使用坐标API插入作业。但我在“GoogleAuthenticationServerDescription”行中遇到错误 错误:“当前上下文中不存在GoogleAuthentic

VisualStudio2010 框架4.0

我正在尝试使用谷歌坐标API插入作业。对于插入作业,我尝试了两种方法。使用webrequest和坐标API。但我无法插入作业。 使用Google坐标API:获取错误“名称空间Google.API中不存在身份验证”

我使用nuget安装了google坐标API。我使用下面的代码使用坐标API插入作业。但我在“GoogleAuthenticationServerDescription”行中遇到错误 错误:“当前上下文中不存在GoogleAuthenticationServerDescription”

注意:我已经导入了Google.Api名称空间,但没有找到

Authentication.OAuth2.DotNetOpenAuth in namespace.

var provider = new WebServerClient(GoogleAuthenticationServer.Description);   
provider.ClientIdentifier =”MyclientID”;
provider.ClientSecret = “MySecretID;
var auth = new OAuth2Authenticator<WebServerClient>(provider, GetAuthorization); 
var service = new CoordinateService(new BaseClientService.Initializer());
Job jobBody = new Job();
jobBody.Kind = "Coordinate#job";
jobBody.State = new JobState();
jobBody.State.Kind = "coordinate#jobState";
jobBody.State.Assignee = "user@example.com";

为什么不使用Google Maps的.NET客户端库呢? ?

看起来您没有使用OAuth 2.0流。您可以在客户机库的文档中了解更多信息-

您还应该查看我们的一个示例,例如,查看,特别是OAuth 2.0代码。您的代码应该如下所示:

 UserCredential credential;
 using (var stream = new FileStream("client_secrets.json",
                                    FileMode.Open, FileAccess.Read))
 {
     credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
         GoogleClientSecrets.Load(stream).Secrets,
         new[] { [CoordinateService.Scope.Coordinate },
         "user", CancellationToken.None,
         new FileDataStore("CredentialsStore"));
 }

 // Create the service.
 var service = new CoordinateService(new BaseClientService.Initializer()
 {
     HttpClientInitializer = credential,
     ApplicationName = "Coordinate .NET library",
 });

 ... and here call one of the service's methods.
更新(10月9日):

我看到您已经更新了上面的代码,但是为什么不使用最新的API—以及我已经提到的最新OAuth 2.0文档—呢


我想你用的是不推荐的

我将检查google.net客户端库并进行更新。我在最初的评论中没有提到,使用web请求的原因是,如果成功,我可以在MS Access VBA代码中实现。您不能用.NET客户端库实现吗?使用.NET客户端库示例代码时,我得到(;)分配凭据变量时出现预期错误我在以下行中遇到编译错误:1)专用异步任务运行()错误:找不到异步,在运行()时遇到分号(;)例外错误。2) credential=Wait GoogleWebAuthorizationBroker.AuthorizationAsync(GoogleClientSecrets.Load(stream.Secrets),新[]{CoordinateService.Scope.Coordinate},“用户”,CancellationToken.None,新文件数据存储(“Coordinate.Auth.Store”);错误:Wait在当前上下文中不存在,并且GoogleWebAuthorizationBroker(所有参数)得到分号(;)除外的错误。我正在Visual Studio 2010上运行此示例注意:我想使用google坐标服务。请更新您的代码并添加stacktrace,这将使其更加清晰
 UserCredential credential;
 using (var stream = new FileStream("client_secrets.json",
                                    FileMode.Open, FileAccess.Read))
 {
     credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
         GoogleClientSecrets.Load(stream).Secrets,
         new[] { [CoordinateService.Scope.Coordinate },
         "user", CancellationToken.None,
         new FileDataStore("CredentialsStore"));
 }

 // Create the service.
 var service = new CoordinateService(new BaseClientService.Initializer()
 {
     HttpClientInitializer = credential,
     ApplicationName = "Coordinate .NET library",
 });

 ... and here call one of the service's methods.