You could also examine the inner exception to find out why the call failed. 
Or set Visual Studio to break on exception.

Cheers,
Anash P. Oommen,
AdWords API Advisor

On Thursday, October 31, 2013 1:44:03 PM UTC-4, cupofcode...@gmail.com 
wrote:
>
> I' have tried to do authorization (console application) with OAuth2 with 
> test mcc account and the code below
>
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
> using System.Threading.Tasks;
> using System.Configuration;
> using Google.Api.Ads.Common;
> using Google.Api.Ads.AdWords.Lib;
> using Google.Api.Ads.Common.Lib;
> using Google.Api.Ads.AdWords.v201309;
> using System.Diagnostics;
> using System.Web;
>
> namespace AdWordsTest
> {
>
>     class Program
>     {
>
>         static void Main(string[] args)
>         {
>             AdWordsUser user = new AdWordsUser();
>             AdWordsAppConfig config = (user.Config as AdWordsAppConfig);
>             if (config.AuthorizationMethod == 
> AdWordsAuthorizationMethod.OAuth2)
>             {
>                 if (config.OAuth2Mode == OAuth2Flow.APPLICATION &&
>                     string.IsNullOrEmpty(config.OAuth2RefreshToken))
>                 {
>                     DoAuth2Authorization(user);
>                 }
>             }
>             else
>             {
>                 throw new Exception("Authorization mode is not OAuth.");
>             }
>
>             Console.Write("Enter the customer id: ");
>             string customerId = 
> config.ClientCustomerId;//Console.ReadLine();
>             //config.ClientCustomerId = customerId;
>
>             // Get the CampaignService.
>             CampaignService campaignService =
>                 
> (CampaignService)user.GetService(AdWordsService.v201309.CampaignService);
>
>             // Create the selector.
>             Selector selector = new Selector();
>             selector.fields = new string[] { "Id", "Name", "Status" };
>
>             // Set the selector paging.
>             selector.paging = new Paging();
>
>             int offset = 0;
>             int pageSize = 500;
>
>             CampaignPage page = new CampaignPage();
>
>            // try
>            // {
>                 do
>                 {
>                     selector.paging.startIndex = offset;
>                     selector.paging.numberResults = pageSize;
>
>                     // Get the campaigns.
>                     page = campaignService.get(selector);
>
>                     // Display the results.
>                     if (page != null && page.entries != null)
>                     {
>                         int i = offset;
>                         foreach (Campaign campaign in page.entries)
>                         {
>                             Console.WriteLine("{0}) Campaign with id = 
> '{1}', name = '{2}' and status = '{3}'" +
>                               " was found.", i + 1, campaign.id, 
> campaign.name, campaign.status);
>                             i++;
>                         }
>                     }
>                     offset += pageSize;
>                 } while (offset < page.totalNumEntries);
>                 Console.WriteLine("Number of campaigns found: {0}", 
> page.totalNumEntries);
>
>             //}
>             //catch (Exception ex)
>             //{
>             //    throw new System.ApplicationException("Failed to 
> retrieve campaigns", ex);
>             //}
>             Console.ReadKey();
>         }
>         private static void DoAuth2Authorization(AdWordsUser user)
>         {
>             // Since we are using a console application, set the callback 
> url to null.
>             user.Config.OAuth2RedirectUri = null;
>             AdsOAuthProviderForApplications oAuth2Provider =
>                 (user.OAuthProvider as AdsOAuthProviderForApplications);
>             // Get the authorization url.
>             string authorizationUrl = oAuth2Provider.GetAuthorizationUrl();
>             Console.WriteLine("Open a fresh web browser and navigate to 
> \n\n{0}\n\n. You will be " +
>                 "prompted to login and then authorize this application to 
> make calls to the " +
>                 "AdWords API. Once approved, you will be presented with an 
> authorization code.",
>                 authorizationUrl);
>             Process.Start(oAuth2Provider.GetAuthorizationUrl());
>             // Accept the OAuth2 authorization code from the user.
>             Console.Write("Enter the authorization code :");
>             string authorizationCode = Console.ReadLine();
>
>             // Fetch the access and refresh tokens.
>             oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode);
>         }
>     }
> }
>
> and the app.config file listed below
>
> <?xml version="1.0" encoding="utf-8"?>
> <configuration>
>   <configSections>
>     <section name="AdWordsApi" 
> type="System.Configuration.DictionarySectionHandler" />
>   </configSections>
>     <startup> 
>         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" 
> />
>     </startup>
> <AdWordsApi>
>     <!--
>       This section contains the settings specific to AdWords and 
> DoubleClick Ad
>       Exchange Buyer 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-adwords-dotnet/wiki/HowToUseAdWordsUser
>       for details.
>
>       You can refer to
>       
> https://code.google.com/p/google-api-adwords-dotnet/wiki/UnderstandingAppConfig
>       for detailed explanation of each configuration key.
>     -->
>
>     <!-- Settings related to SOAP logging. -->
>     <add key="LogPath" value="C:\Logs\" />
>     <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. -->
>     <!-- <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.-->
>     <add key="EnableGzipCompression" value="true" />
>
>     <!-- Proxy settings for library. -->
>     <add key="ProxyServer" value="" />
>     <add key="ProxyUser" value="" />
>     <add key="ProxyPassword" value="" />
>     <add key="ProxyDomain" value="" />
>
>     <!-- Settings specific to AdWords API.-->
>     <add key="UserAgent" value="AdWordEasyExtractor" />
>     <add key="DeveloperToken" value="qsGTV0yTRd1kEte7ux2rlg" />
>
>     <!-- If your application is a simple script that makes calls to only a
>          single Adwords account, then you can set your customer ID here. 
> If you
>          have multiple customer IDs to deal with in your account, then you 
> can
>          comment out this key and set the value at runtime by setting
>          ((AdWordsAppConfig) user.Config).ClientCustomerId = "xxx";
>     -->
>     <add key="ClientCustomerId" value="434-888-4204" />
>
>     <!-- 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-adwords-dotnet/wiki/UsingOAuth
>          for more details.
>     -->
>     <add key="OAuth2ClientId" value="
> 298178896275-lsbau2r08g61rmdme3n47mbvgpagolur.apps.googleusercontent.com" 
> />
>     <add key="OAuth2ClientSecret" value="NszeV1LQwe0k4ZglDgLDhw-P" />
>
>     <!-- The following OAuth2 settings are optional. -->
>     <!-- Provide a different OAuth2 scope if required. Multiple scopes 
> should be
>          separated by spaces. -->
>      <add key="OAuth2Scope" value="https://adwords.google.com/api/adwords/"; 
> /> 
>
>     <!-- Use the following keys if you want to use Web / Installed 
> application
>          OAuth flow.-->
>
>     <add key="OAuth2Mode" value="APPLICATION" />
>     <!-- If you are using a single MCC account's credentials to make calls 
> to
>          all your accounts, 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 
> unrelated
>          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="" />
>
>     <!-- 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/adwords/api/docs/guides/service-accounts
>          and 
> https://code.google.com/p/google-api-adwords-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" />
>     -->
>
>     <!-- Settings specific to use ClientLogin as authentication mechanism. 
> -->
>     <!-- To use ClientLogin as authentication mechanism, uncomment the 
> following
>          section and comment the OAuth2 section above. Keep in mind that
>          ClientLogin API is deprecated, and its use is strongly 
> discouraged.
>          See 
> https://developers.google.com/accounts/docs/AuthForInstalledApps
>          for details.-->
>     <!--
>     <add key="AuthorizationMethod" value="ClientLogin" />
>     <add key="Email" value="INSERT_YOUR_LOGIN_EMAIL_HERE"/>
>     <add key="Password" value="INSERT_YOUR_PASSWORD_HERE"/>
>     -->
>     <!-- Optional: uncomment this if you want to reuse an authToken 
> multiple
>          times. -->
>     <!-- <add key="AuthToken" value="INSERT_YOUR_AUTH_TOKEN_HERE"/> -->
>   </AdWordsApi><system.web>
>     <webServices>
>       <soapExtensionTypes>
>         <add type="Google.Api.Ads.Common.Lib.SoapListenerExtension, 
> Google.Ads.Common" priority="1" group="0" />
>       </soapExtensionTypes>
>     </webServices>
>   </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>
>
>
>
> But unfortunately i got the error on the line "page = 
> campaignService.get(selector);", with text "failed to retrieve campaigns"
>
> Could you suggest me, what is wrong? 
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to