tell me please where is mistake? i'am trying create sandbox campaign
in .NET
instead of "my-google-email" i enter my real email, "my-google-
password" replaced by my real password.
It is all. webRequest.GetResponse() return error 500 ("inner server
error")
public static void CreateCampaign()
{
//https://sandbox.google.com/api/adwords/v13/CampaignService?
wsdl
//https://sandbox.google.com/api/adwords/v13
//https://adwords.google.com/api/adwords/cm/v200909
string authToken = GetAuthToken();
string requestXml = string.Format(@"
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/
envelope/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<soap:Header>
<RequestHeader xmlns='https://sandbox.google.com/api/adwords/
v13'>
<applicationToken>{0}</applicationToken>
<authToken>{1}</authToken>
<clientEmail>{2}</clientEmail>
<developerToken>{3}</developerToken>
<userAgent>{4}</userAgent>
</RequestHeader>
</soap:Header>
<soap:Body>
<mutate xmlns='https://sandbox.google.com/api/adwords/v13'>
<operations>
<operator>ADD</operator>
<operand>
<name>Interplanetary Cruise#111</name>
<status>PAUSED</status>
<budget>
<period>DAILY</period>
<amount>
<microAmount>50000000</microAmount>
</amount>
<deliveryMethod>STANDARD</deliveryMethod>
</budget>
<biddingStrategy xsi:type='ManualCPC' />
</operand>
</operations>
</mutate>
</soap:Body>
</soap:Envelope>",
"", authToken, "",
"my-google-email++USD", "somewords").Trim();
WebRequest webRequest = HttpWebRequest.Create(
"https://sandbox.google.com/api/adwords/v13/
CampaignService");
webRequest.Method = "POST";
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Headers.Add("SOAPAction", "");
byte[] postBytes = Encoding.UTF8.GetBytes(requestXml);
webRequest.ContentLength = postBytes.Length;
using (Stream strmReq = webRequest.GetRequestStream())
{
strmReq.Write(postBytes, 0, postBytes.Length);
}
try
{
WebResponse response = webRequest.GetResponse();
}
catch (WebException ex)
{
throw new ApplicationException("Could not make Api call.",
ex);
}
}
Here GetAuthToken() is
private static string GetAuthToken()
{
WebRequest webRequest = HttpWebRequest.Create("https://
www.google.com/accounts/ClientLogin");
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
string postParams =
"accountType=" + HttpUtility.UrlEncode("GOOGLE") +
"&Email=" + HttpUtility.UrlEncode("my-google-email") +
"&Passwd=" + HttpUtility.UrlEncode("my-google-password") +
"&service=" + HttpUtility.UrlEncode("adwords") +
"&source=" + HttpUtility.UrlEncode(string.Format("{0}-{1}-
{2}", "YOUR_COMPANY_NAME",
"YOUR_APP_NAME", "YOUR_VERSION_ID"));
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;
}
what is wrong here?
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en