understanding app.config - jimper/googleads-dotnet-lib GitHub Wiki

Introduction

Ads API Client library provides several configuration settings that you can use to customize the library behavior. You may configure the library beforehand using your application's App.config / Web.config, or delay the configuration until runtime. This page explains the settings as they appear in App.config. If you don't want to use App.config, you can affect the same configuration at runtime as follows:

AdWordsUser user = new AdWordsUser();
AdWordsAppConfig config = (AdWordsAppConfig) user.Config;
config.DeveloperToken = "xxx";

Settings specific to a supported API are stored under its own node:

  • Settings for AdWords API and AdxBuyer APIs are stored under the AdWordsApi node
  • Settings for DFP API is stored under the DfpApi node

Logging

The Ads API .NET library uses System.Trace to log SOAP and request messages and print various deprecation and warning messages. You can configure this behavior by adding the following node in your App.config.

  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="Google.Api.Ads.Common.Lib.SoapListenerExtension, Google.Ads.Common"
             priority="1" group="0"/>
      </soapExtensionTypes>
    </webServices>
  </system.web>
  <system.diagnostics>
    <sources>
      <source name="AdsClientLibs.DeprecationMessages"
        switchName="AdsClientLibs.DeprecationMessages"
        switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="myListener"
            type="System.Diagnostics.EventLogTraceListener"
            initializeData="Application" />
        </listeners>
      </source>
      <source name="AdsClientLibs.SoapXmlLogs"
        switchName="AdsClientLibs.SoapXmlLogs"
        switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <!-- Modify the initializeData attribute below to control the
                path to the SOAP XML log file. -->
          <add name="soapXmlLogListener"
            type="System.Diagnostics.TextWriterTraceListener"
            initializeData="C:\Logs\soap_xml.log" />
          <remove name="Default" />
        </listeners>
      </source>
      <source name="AdsClientLibs.RequestInfoLogs"
        switchName="AdsClientLibs.RequestInfoLogs"
        switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <!-- Modify the initializeData attribute below to control the
                path to the request info log file. -->
          <add name="requestInfoLogListener"
            type="System.Diagnostics.TextWriterTraceListener"
            initializeData="C:\Logs\request_info.log" />
          <remove name="Default" />
        </listeners>
      </source>
    </sources>
    <switches>
      <!-- Use this trace switch to control the deprecation trace messages
          written by Ads* .NET libraries. The default is level is set to
          Warning. To disable all messages, set this value to Off. See
          http://msdn.microsoft.com/en-us/library/system.diagnostics.sourcelevels.aspx
          for all possible values this key can take. -->
      <add name="AdsClientLibs.DeprecationMessages" value="Warning"/>
      <!-- Use this trace switch to control the SOAP XML logs written by Ads*
          .NET libraries. The default level is set to Off. Logs are generated
          at both the Error and Information levels. -->
      <add name="AdsClientLibs.SoapXmlLogs" value="Off"/>
      <!-- Use this trace switch to control the Request Info logs written by
          Ads* .NET libraries. The default level is set to Off. Logs are
          generated at both the Error and Information levels. -->
      <add name="AdsClientLibs.RequestInfoLogs" value="Off"/>
    </switches>
    <trace autoflush="true" />
  </system.diagnostics>

If you used the LogPath, LogToFile and LogErrorsOnly settings in the past, then you can achieve a similar configuration as follows:

Setting Value Legacy Setting Legacy Value Result/Behavior
initializeData in soapXmlLogListener and requestInfoLogListener filename LogPath filename Specifies the file to which logs will be written
AdsClientLibs.SoapXmlLogs trace switch Off LogToFile false Turn off logging
AdsClientLibs.SoapXmlLogs trace switch Info LogErrorsOnly false Log all requests
AdsClientLibs.SoapXmlLogs trace switch Error LogErrorsOnly true Log only failed requests

General library behavior

These settings are common to client libraries, and not tied to an API version.

  • RetryCount: Use this key to automatically retry a call that failed due to a recoverable error like expired credentials or a transient error like RateExceededError.
  • Timeout: Use this key to set service timeout in milliseconds. Set this to -1 if you never want the service to timeout. See http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx for details.
  • ProxyServer: Set this to the HTTP proxy server URL if you are using a proxy to connect to the internet.
  • ProxyUser: Set this to the username you require to authenticate against the proxy server. Leave this empty if a username is not required.
  • ProxyPassword: Set this to the password of ProxyUser if you set a value for ProxyUser.
  • ProxyDomain: Set this to the domain for ProxyUser if your proxy server requires one to be set.
  • EnableGzipCompression: Set this to true to use HTTP compression while talking to the Adwords server.

OAuth2 configuration

When using OAuth2 to authenticate your calls against various Ads API servers, you should set the following configuration keys:

  • AuthorizationMethod: This should be set to OAuth2.
  • OAuth2Mode: This should be set to APPLICATION or SERVICE_ACCOUNT
  • OAuth2ClientId: Set this value to your OAuth2 client id.
  • OAuth2ClientSecret: Set this value to your OAuth2 client secret.
  • OAuth2Scope: Set this value to different scopes if you want to authorize OAuth2 tokens for multiple APIs. This setting is optional.

If you are using OAuth2Mode == APPLICATION, then you need to set the following additional configuration keys.

  • OAuth2RefreshToken: Set this value to a pre-generated OAuth2 refresh token if you wish to reuse OAuth2 tokens. This setting is optional.
  • OAuth2RedirectUri: Set this value to the OAuth2 redirect url. This setting is optional.

If you are using OAuth2Mode == SERVICE_ACCOUNT, then you need to set the following additional configuration keys.

  • OAuth2ServiceAccountEmail: Set this value to the service account email being used to make calls.
  • OAuth2PrnEmail: Set this value to the login email of the account you are impersonating.
  • OAuth2JwtCertificatePath: Set this value to the OAuth2 JWT certficate path.
  • OAuth2JwtCertificatePassword: Set this value to the OAuth2 JWT certificate password.

AdWords API configuration

The following settings are specific to AdWords API.

  • UserAgent: Set this to a string of your choice, ideally your company name, application name or any other unique string.
  • DeveloperToken: Set this to your developer token.
  • ClientCustomerId: Set this to the customer id of your client account.

The following settings are specific to ReportUtilities class in AdWords API client library.

  • SkipReportHeader: Set this flag to skip the report header (report name, generated on, etc.) in CSV, TSV or their gzipped formats.
  • SkipReportSummary: Set this flag to skip the report summary footer in CSV, TSV or their gzipped formats.
  • SkipColumnHeader: Set this flag to skip the report column headers in CSV, TSV or their gzipped formats.
  • IncludeZeroImpressions: Set this flag to include zero impression rows when downloading a report. If this setting is commented out, then the server behaves as explained in https://developers.google.com/adwords/api/docs/guides/zero-impression-reports#default_behavior.

DFP API configuration

The following settings are specific to DFP API.

  • ApplicationName: Set this to your DFP API application name.
  • NetworkCode: Set your DFP API network code here.

Miscellaneous settings

The .NET runtime trims the error response to 64K by default. To disable this setting, you need to add the following node to your App.config.

<system.net>
  <settings>
    <httpWebRequest maximumErrorResponseLength="-1"  />
  </settings>
</system.net>
⚠️ **GitHub.com Fallback** ⚠️