0

我正在尝试在我的 .Net Web 应用程序中访问 google DFA API。我在 web.config 文件中提供了所有重要信息。即
` https://code.google.com/p/google-api-dfa-dotnet/wiki/HowToUseADfaUser 了解详情。

      You can refer to
      https://code.google.com/p/google-api-dfa-dotnet/wiki/UnderstandingAppConfig
      for detailed explanation of each configuration key.
    -->

    <!-- Settings related to SOAP logging. -->
    <!--
      This section contains the settings specific to the Google's DoubleClick
      for Advertisers API DotNet Client Library. You can use the App.config /
      Web.config for quickly configuring and running a simple application.
      However, it is not mandatory to provide your settings in the config file,
      you may also set or override these settings at runtime. See
      https://code.google.com/p/google-api-dfa-dotnet/wiki/HowToUseADfaUser
      for details.

      You can refer to
      https://code.google.com/p/google-api-dfa-dotnet/wiki/UnderstandingAppConfig
      for detailed explanation of each configuration key.
    --><!-- Settings related to SOAP logging. --><add key="LogPath" value="C:\Logs\Dfa\" />
    <add key="LogToFile" value="false" />
    <add key="MaskCredentials" value="true" />
    <add key="LogErrorsOnly" value="true" />

    <!-- Settings related to general library behaviour. -->

    <!-- Use this key to automatically retry a call that failed due to a
         recoverable error like expired credentials. -->
    <!-- Settings related to general library behaviour. --><!-- Use this key to automatically retry a call that failed due to a
         recoverable error like expired credentials. --><add key="RetryCount" value="1" />

    <!-- Set the service timeout in milliseconds. -->
    <!-- <add key="Timeout" value="100000"/> -->

    <!-- Use this key to enable or disable gzip compression in SOAP requests.-->
    <!-- Set the service timeout in milliseconds. --><!-- <add key="Timeout" value="100000"/> --><!-- Use this key to enable or disable gzip compression in SOAP requests.--><add key="EnableGzipCompression" value="true" />

    <!-- Proxy settings for library. -->
    <!-- Proxy settings for library. --><add key="ProxyServer" value="" />
    <add key="ProxyUser" value="" />
    <add key="ProxyPassword" value="" />
    <add key="ProxyDomain" value="" />

    <!-- Settings specific to DFA API. -->
    <!-- Set a friendly name to identify your application. -->
    <!-- Settings specific to DFA API. --><!-- Set a friendly name to identify your application. --><add key="ApplicationName" value="My App" />

     <!--Uncomment this key if you want to use DFA test environment.--> 
     <add key="DfaApi.Server" value="https://advertisersapitest.doubleclick.net"/> 

    <!-- Uncomment this key if you want to use DFA beta environment. -->
    <!-- <add key="DfaApi.Server" value="http://betaadvertisersapi.doubleclick.net"/> -->

    <!-- Set the Authorization method to be used with the client library. -->
    <!-- To use LoginService as authentication mechanism, uncomment the following
         section and comment the OAuth2 section below. -->

    <!--<add key="AuthorizationMethod" value="LoginService" />
    <add key="DfaUserName" value="" />
    <add key="DfaPassword" value="" />-->

    <!-- Uncomment this key if you want to reuse an authToken returned by
         LoginRemoteService multiple times. -->
    <!-- <add key="DfaAuthToken" value="ENTER_YOUR_DFA_AUTH_TOKEN_HERE"/> -->

    <!-- Settings specific to use OAuth2 as authentication mechanism. You could
         run Common\Util\OAuth2TokenGenerator.cs to generate this section of the
         config file.
    -->

    <!-- Uncomment this key if you want to use DFA test environment. --> <!--<add key="DfaApi.Server" value="https://advertisersapitest.doubleclick.net"/>--> <!-- Uncomment this key if you want to use DFA beta environment. --><!-- <add key="DfaApi.Server" value="http://betaadvertisersapi.doubleclick.net"/> --><!-- Set the Authorization method to be used with the client library. --><!-- To use LoginService as authentication mechanism, uncomment the following
         section and comment the OAuth2 section below. --><!--<add key="AuthorizationMethod" value="OAuth2" />-->
    <!-- Provide the OAuth2 client ID and secret. You can create one from
         https://code.google.com/apis/console/. See
         https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth
         for more details.
    -->

    <add key="AuthorizationMethod" value="OAuth2" />
    <add key="OAuth2Mode" value="APPLICATION" /> 
    <add key="OAuth2ClientId" value="741571964664-m4kpcsris5s0g6meufb4jofria0fm6s2.apps.googleusercontent.com" />
    <add key="OAuth2ClientSecret" value="xqYh16LPvixcdk-BS3M9gZLw" />
    <add key="DfaAuthToken" value="AIzaSyDjLEiomKRThlJExMDra-Ck7qvZWJNK-3M"/>
    <add key="OAuth2RefreshToken" value="1/fKT0ObQy19dmZA51zVJDMtv2IeaGCGaS9rlTkCDPfeA" />
    <add key="OAuth2RedirectUri" value="https://developers.google.com/oauthplayground" />
    <add key="DfaUserName" value="My_DFA_UserName" />
    <add key="DfaPassword" value="My_DFA_Password" />
    <!-- The following OAuth2 settings are optional. -->
    <!-- Provide a different OAuth2 scope if required. Multiple scopes should be
         separated by spaces. -->
    <!-- <add key="OAuth2Scope" value="INSERT_OAUTH2_SCOPE_HERE" /> -->

    <!-- Use the following keys if you want to use Web / Installed application
         OAuth flow.-->

    <!-- <add key="OAuth2Mode" value="APPLICATION" /> -->
    <!-- If you have only a single sount, then you can run
         OAuth2TokenGenerator.cs to generate a RefreshToken for that account and
         set this key in your application's App.config / Web.config. If you are
         making calls to multiple accounts, then you need to implement OAuth2
         flow in your account and set this key at runtime. See OAuth folder
         under Examples folder for a web and a console application example.
    -->
    <!-- <add key="OAuth2RefreshToken" value="INSERT_OAUTH2_REFRESH_TOKEN_HERE" /> -->

    <!-- Optional: Specify an OAuth2 redirect url if you are building a
         web application and implementing OAuth2 web flow in your application.
    -->
    <!-- <add key="OAuth2RedirectUri" value="" /> -->


    <!-- Use the following keys if you want to use OAuth2 service account flow.
         You should comment out all the keys for Web / Installed application
         OAuth flow above. See
         https://developers.google.com/doubleclick-publishers/docs/service_accounts
         and https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth
         for more details.
    -->
    <!--
    <add key="OAuth2Mode" value="SERVICE_ACCOUNT" />
    <add key="OAuth2ServiceAccountEmail"
        value="INSERT_OAUTH2_SERVICE_ACCOUNT_EMAIL_HERE" />
    <add key="OAuth2PrnEmail" value="INSERT_OAUTH2_USER_EMAIL_HERE" />
    <add key="OAuth2JwtCertificatePath"
        value="INSERT_OAUTH2_JWT_CERTIFICATE_PATH_HERE" />
    <add key="OAuth2JwtCertificatePassword"
        value="INSERT_OAUTH2_JWT_CERTIFICATE_PASSWORD_HERE" />
    -->
  <!--<add key="AuthorizationMethod" value="LoginService " /><add key="DfaUserName" value="" /><add key="DfaPassword"  value="" />--><!-- Uncomment this key if you want to reuse an authToken returned by
         LoginRemoteService multiple times. --> <!--<add key="DfaAuthToken" value="AIzaSyDjLEiomKRThlJExMDra-Ck7qvZWJNK-3M"/>--> <!-- Settings specific to use OAuth2 as authentication mechanism. You could
         run Common\Util\OAuth2TokenGenerator.cs to generate this section of the
         config file.
    --> <!--<add key="AuthorizationMethod" value="OAuth2" />--> <!-- Provide the OAuth2 client ID and secret. You can create one from
         https://code.google.com/apis/console/. See
         https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth
         for more details.
    -->

    <!--<add key="OAuth2ClientId" value="741571964664.apps.googleusercontent.com" />
    <add key="OAuth2ClientSecret" value="mSU3WGHlwGkDn9IVvGVf-3R0" />-->
    <!-- The following OAuth2 settings are optional. --><!-- Provide a different OAuth2 scope if required. Multiple scopes should be
         separated by spaces. --><!-- <add key="OAuth2Scope" value="INSERT_OAUTH2_SCOPE_HERE" /> --><!-- Use the following keys if you want to use Web / Installed application
         OAuth flow.--><!-- <add key="OAuth2Mode" value="APPLICATION" /> --><!-- If you have only a single account, then you can run
         OAuth2TokenGenerator.cs to generate a RefreshToken for that account and
         set this key in your application's App.config / Web.config. If you are
         making calls to multiple accounts, then you need to implement OAuth2
         flow in your account and set this key at runtime. See OAuth folder
         under Examples folder for a web and a console application example.
    -->  <!-- Optional: Specify an OAuth2 redirect url if you are building a
         web application and implementing OAuth2 web flow in your application.
    --><!-- <add key="OAuth2RedirectUri" value="" /> --><!-- Use the following keys if you want to use OAuth2 service account flow.
         You should comment out all the keys for Web / Installed application
         OAuth flow above. See
         https://developers.google.com/doubleclick-publishers/docs/service_accounts
         and https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth
         for more details.
    --><!--
    <add key="OAuth2Mode" value="SERVICE_ACCOUNT" />
    <add key="OAuth2ServiceAccountEmail"
        value="INSERT_OAUTH2_SERVICE_ACCOUNT_EMAIL_HERE" />
    <add key="OAuth2PrnEmail" value="INSERT_OAUTH2_USER_EMAIL_HERE" />
    <add key="OAuth2JwtCertificatePath"
        value="INSERT_OAUTH2_JWT_CERTIFICATE_PATH_HERE" />
    <add key="OAuth2JwtCertificatePassword"
        value="INSERT_OAUTH2_JWT_CERTIFICATE_PASSWORD_HERE" />
    --></DfaApi>
  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="Google.Api.Ads.Common.Lib.SoapListenerExtension, Google.Ads.Common" priority="1" group="0" />
      </soapExtensionTypes>
    </webServices>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.net>
    <settings>
      <httpWebRequest maximumErrorResponseLength="-1" />
    </settings>
  </system.net>
<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></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" /></switches></system.diagnostics></configuration>
`
and my code snippet is `


    public override AdvertiserRecordSet Run(DfaUser user)
        {


            // Create AdvertiserRemoteService instance.
            AdvertiserRemoteService service = (AdvertiserRemoteService)user.GetService(DfaService.v1_19.AdvertiserRemoteService);

            String searchString = _T("");

            // Create advertiser search criteria structure.
            AdvertiserSearchCriteria advSearchCriteria = new AdvertiserSearchCriteria();
            advSearchCriteria.pageSize = 10;
            advSearchCriteria.searchString = searchString;
            string str = service.RequestHeader.TargetNamespace.ToString();


            try
            {
                // Get advertiser record set.
                AdvertiserRecordSet recordSet = service.getAdvertisers(advSearchCriteria);

                // Display advertiser names, ids and spotlight configuration ids.
                if (recordSet.records != null)
                {
                    foreach (Advertiser result in recordSet.records)
                    {
                        //Console.WriteLine("Advertiser with name \"{0}\", id \"{1}\", and spotlight " +
                        //    "configuration id \"{2}\" was found.", result.name, result.id, result.spotId);
                    }
                    return recordSet;
                }
                else
                {
                    Console.WriteLine("No advertisers found for your criteria.");
                }
            }
            catch (Exception ex)
            {
              //  Console.WriteLine("Failed to retrieve advertisers. Exception says \"{0}\"", ex.Message);
            }

            return null;
        }
`   
I am stuck here.Please help to find out the solution.
Regards.
4

0 回答 0