我正在尝试访问 Google Adwords Sandbox API,但我无法弄清楚发生了什么。
这是我的代码:
var wsUrl = "https://adwords-sandbox.google.com/api/adwords/cm/v201008/CampaignService";
var soapRequest =
'<soapenv:Envelope \
xmlns:soapenv="http://schemax.xmlsoap.org/soap/envelope/" \
xmlns="https://adwords.google.com/api/adwords/cm/v200906"> \
<soapenv:Header> \
<service>adwords</service> \
<email>***@gmail.com</email> \
<password>***</password> \
<developerToken>***@gmail.com++USD</developerToken> \
<useragent>MyApplication</useragent> \
</soapenv:Header> \
<soapenv:Body> \
<getClientAccounts/> \
</soapenv:Body> \
</soapenv:Envelope>';
$.ajax({
type: "GET",
url: wsUrl,
contentType: document.body,
crossDomain: true,
dataType: "jsonp",
data: soapRequest,
success: processSuccess,
error: processError
});
});
function processSuccess(data, status, req) {
if (status == "success")
console.log("success");
}
function processError(data, status, req) {
console.log("status = " + status + " data= " + data );
}
我不断收到 500 个内部服务器错误。我究竟做错了什么?!在 Google Adwords Sandbox 网站上,他们列出了简单的说明:
To create a sandbox account, send a get request to the sandbox version of CampaignService, using the WSDL location and sandbox headers as described below. This initial call to the sandbox creates an MCC sandbox account, along with five client accounts, for the email address you specified. Your sandbox account and its client accounts start out empty. http://code.google.com/apis/adwords/docs/sandbox.html
帮助!
最佳答案
AdWords API 是一种 SOAP API,因此无法以 JSONP 形式发送数据。此外,带有 cross-domain=true 的 $.ajax 仅适用于 JSON 或 JSONP 变体,除此之外的任何内容都将被浏览器的跨域策略阻止。
您可以尝试探索 AdWords API Javascript 客户端库 - 请参阅 http://code.google.com/p/google-api-adwords-js/了解详情。
我们的主要讨论论坛位于 http://groups.google.com/group/adwords-api?pli=1 ,我经常在那里回答开发人员的问题,所以如果您有任何后续问题,请随时在那里提问,我很乐意回答您的问题。
干杯, Anash P. Oommen
关于javascript - 使用 SOAP 和 Javascript (Google Adwords Sandbox API) 发送 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7427218/