javascript - 使用 SOAP 和 Javascript (Google Adwords Sandbox API) 发送 GET 请求

标签 javascript soap google-ads-api

我正在尝试访问 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/

相关文章:

soap - 如何在不检查 Content-Type header 的情况下使 jaxws 解析响应

javascript - 与表单的提交按钮配合使用的 Google AdWords 转化跟踪

当我有一项事件时 Admob 多个广告单元

google-analytics - 在联系表单中显示 AdWords 广告系列

Javascript 将 html 标签的颜色设置回默认颜色而不是假设颜色为黑色

javascript - jQuery 通过波斯数字转换拉丁数字

javascript - 没有 Javascript 的 capybara Click_Button 失败

javascript - 如何防止在knockout.js自定义绑定(bind)中递归调用更新和值更改回调?

Eclipse Birt 未处理的事件循环异常

soap - 寻找 Java 库/API 来为带有附件的 SOAP 消息实现 WS-Security(SwA)