【问题标题】:Possible file missing for Google .net APIGoogle .net API 可能缺少文件
【发布时间】:2014-09-16 20:14:30
【问题描述】:

当我尝试对请求调用 .Execute() 时,系统会要求我在我的计算机上找到 ClientServiceRequest.cs。我以为这将包含在 NuGet 包中,但它没有,我找不到任何关于我应该如何或在哪里获得它或它包含在什么中的任何信息。以前有没有人经历过这样的事情?

需要详细说明-

static void Main(string[] args)
{
   var ics = new BaseClientService.Initializer
   {
       ApplicationName = "appname",
       ApiKey = "[APIkey]",
   } as IClientService;
   var inst = new InstancesResource.GetRequest(ics, "project-name",
       "zone", "exampleinstance");
   var instresponse = inst.Execute();          //Error is on this line
   instresponse.Name = "geninstance";
   var instinsert = new InstancesResource.InsertRequest(ics, 
       instresponse, "projectname", "zone");
   instinsert.Execute();
}

我第一次运行此代码时,它给了我一个窗口来浏览我的计算机并希望我找到“ClientServiceRequest.cs”,我已经搜索过它,但没有找到所以我在浏览窗口上单击取消,然后在上面提到的行上抛出 NullReferenceException,之后每次运行代码时都会抛出异常。

请告诉我我的代码是否愚蠢,很可能是因为我在尝试测试时遇到了这个错误。

【问题讨论】:

  • 抓取了哪个 nugget 包?
  • 我安装了“Google.Apis”和“Google.Apis.Compute.v1”当我尝试执行InstanceResources.GetRequest时出现问题
  • 你能贴一些代码吗?
  • 你能发布你得到的确切错误吗?源代码可以在这里获得:code.google.com/p/google-api-dotnet-client/source/browse/Src/…
  • 我刚刚编辑了问题以提供更多信息。如果我必须下载任何源代码,您将它放在哪里最明智?感谢您的帮助!

标签: google-api-dotnet-client


【解决方案1】:

感谢 peleyal 的帮助,问题得到了很好的解答,代码需要 OAuth 2.0,我必须下载 .net api 的源代码。记录在案-

var ics = new BaseClientService.Initializer
{
    ApplicationName = "appname",
    ApiKey = "[APIkey]",
} as IClientService;

不是天才,甚至可能都行不通。使用起来更明智-

var cs = new ComputeService(new BaseClientService.Initializer
    {
        ApplicationName = "appname",
        ApiKey = "[APIKEY]",
    });

像普通人一样,无论在问题代码中使用 ics 的任何地方都可以工作。

谢谢大家!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 2013-06-16
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多