【问题标题】:Adwords API C# : use web.config with class libraryAdwords API C#:将 web.config 与类库一起使用
【发布时间】:2011-10-31 13:53:05
【问题描述】:

我正在构建 ASP.Net MVC 应用程序并希望集成 adwords API 的功能。

我在我的项目中为此创建了一个类库,在某些类中具有这些功能。

在我的类库中,我像这样实例化 AdWordsUser:

var user = new AdWordsUser();

但是当我在我的网络项目中使用我的库时,它不会读取 web.config 文件中的 adwords 配置。

所以我尝试像这样以编程方式传递配置:

var config = new Dictionary<string, string>();

config.Add("EnableGzipCompression", "true");
config.Add("UserAgent", "xxxx");
config.Add("DeveloperToken", "xxxxx");
config.Add("ClientCustomerId", "xxxxx");
config.Add("AuthorizationMethod", "ClientLogin");
config.Add("Email", "xxxxx@xxxxxxx.xxx");
config.Add("Password", "xxxxx");

this.CurrentAdwordsUser = new AdWordsUser(config);

但它告诉我它不能将字符串转换为布尔值。

有人知道怎么做吗?

【问题讨论】:

  • 在哪里出现错误?
  • 当我执行查询时。但这似乎是因为它等待配置强类型,但 AdWordsUser 的构造函数只采用 Dictionary...

标签: c# asp.net google-ads-api


【解决方案1】:

这里的问题是 AdWordsUser(headers) 构造函数是一种已弃用的标头方法,为了从 v13 API 向后兼容而维护(大部分已弃用,但仍可供开发人员使用)。它只需要转换成字符串的 SOAP 标头,没有配置参数。

你需要的是这个:

this.CurrentAdwordsUser = new AdWordsUser();
(this.CurrentAdwordsUser.Config as AdWordsAppConfig).EnableGzipCompression = true;

对任何其他配置设置执行类似操作。

顺便说一句,您可能想在官方 AdWords API 论坛上发布任何后续问题,因为该库的当前维护者会对其进行监控:

http://code.google.com/apis/adwords/forum.html

干杯, 阿纳什

【讨论】:

    【解决方案2】:

    我认为问题可能在于您传递的是“true”而不是 True。如果你认为这是一个错误,你可以在这里打开一个问题:http://code.google.com/p/google-api-adwords-dotnet/issues/list

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      • 2019-11-14
      • 1970-01-01
      • 2010-11-01
      • 2016-02-19
      相关资源
      最近更新 更多