Hi Jo,

The problem comes from the AdWordsUser constructor: it try to authenticate 
the user before applying the proxy settings...

I use a method which get the authtoken and use another method to instantiate 
the AdWordsUser to solve the problem.

To get the authtoken:

public static string GetAuthToken()
        {
            WebRequest webRequest = 
HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin";);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";

            WebProxy proxy = new WebProxy("myProxy", port);
            NetworkCredential credentials = new NetworkCredential();
            credentials.UserName = "username";
            credentials.Password = "pwd";
            credentials.Domain = "mydomain";
            proxy.Credentials = credentials;

            webRequest.Proxy = proxy;
            

            

            string postParams =
                "accountType=" + HttpUtility.UrlEncode("GOOGLE") +
                "&Email=" + HttpUtility.UrlEncode("") +
                "&Passwd=" + HttpUtility.UrlEncode("") +
                "&service=" + HttpUtility.UrlEncode("adwords") +
                "&source=" + 
HttpUtility.UrlEncode(string.Format("{0}-{1}-{2}", "",
                    "", "0.0"));

            byte[] postBytes = Encoding.UTF8.GetBytes(postParams);
            webRequest.ContentLength = postBytes.Length;

            using (Stream strmReq = webRequest.GetRequestStream())
            {
                strmReq.Write(postBytes, 0, postBytes.Length);
            }

            string retVal = "";
            try
            {
                WebResponse response = webRequest.GetResponse();

                using (StreamReader reader = new 
StreamReader(response.GetResponseStream()))
                {
                    string sResponse = reader.ReadToEnd();
                    string[] splits = sResponse.Split('\n');
                    foreach (string split in splits)
                    {
                        string[] subsplits = split.Split('=');
                        if (subsplits.Length >= 2 && subsplits[0] == "Auth")
                        {
                            retVal = subsplits[1];
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                throw new ApplicationException("Could not generate auth 
token.", ex);
            }
            return retVal;
        }


The AdWordsUser instantiation:

       Dictionary<String, String> dic = new Dictionary<String, String>();
        dic.Add("authToken", GetAuthToken() );
        
        AdWordsUser user = new AdWordsUser(dic);
        user.Config.Proxy.Address = new Uri("http://yourProxy:port";);
        NetworkCredential cred = new NetworkCredential();
        cred.UserName="";
        cred.Password="";
        cred.Domain="";
        user.Config.Proxy.Credentials = cred;

You can use the API now!

Thomas

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.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

Reply via email to