-
Notifications
You must be signed in to change notification settings - Fork 198
Understanding App.config
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 is stored under the
AdWordsApi
node - Settings for Google Ad Manager API is stored under the
AdManagerApi
node
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.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.DetailedRequestLogs"
switchName="AdsClientLibs.DetailedRequestLogs"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="detailedRequestLogListener" type="System.Diagnostics.ConsoleTraceListener"
initializeData="true"/>
<!-- Use the following to log to file. Modify the initializeData
attribute to control the path to the detailed request log file.
<add name="detailedRequestLogListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Logs\detailed_logs.log"/>
-->
<remove name="Default"/>
</listeners>
</source>
<source name="AdsClientLibs.SummaryRequestLogs" switchName="AdsClientLibs.SummaryRequestLogs"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="summaryRequestLogListener" type="System.Diagnostics.ConsoleTraceListener"
initializeData="true"/>
<!-- Use the following to log to file. Modify the initializeData
attribute to control the path to the summary request log file.
<add name="summaryRequestLogListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Logs\summary_logs.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 detailed request 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.DetailedRequestLogs" value="Off"/>
<!-- Use this trace switch to control the summary request 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.SummaryRequestLogs" value="Off"/>
</switches>
<trace autoflush="true"/>
</system.diagnostics>
Note: Logging configuration through App.config is not supported for .NET Core. See alternative.
These settings are common to client libraries, and not tied to an API version.
- 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 forProxyUser
. -
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.
- IncludeUtilitiesInUserAgent: Set this value to true to allow the client library to append the list of identifiers for various utility classes used in the client library, as part of the user agent.
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
orSERVICE_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.
See the following guides for more details:
- API access on behalf of your clients (webflow)
- API access using own credentials (installed application flow)
If you are using OAuth2Mode == SERVICE_ACCOUNT
, then you need to set the following additional configuration keys.
- OAuth2PrnEmail: Set this value to the login email of the account you are impersonating.
- OAuth2SecretsJsonPath: Set this value to the OAuth2 JSON configuration file path.
See the following guide for more details:
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.
- UseRawEnumValues: Set this flag to return enum values as actual enum values instead of display values 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/reporting#request-headers.
The following settings are specific to Google Ad Manager API
- ApplicationName: Set this to your Google Ad Manager API application name.
- NetworkCode: Set your Google Ad Manager API network code here.
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>