Google Adwords API

來源:互聯網
上載者:User

Google Adwords API 分正式API和測試API。

基中正式API是需要收取費用,Google將以API單位收費;而測試API(Sandbox)中的則不收取任何費用,但有些API返回的結果是Google定義好的,不怎麼好測試!Google也是近期剛發布的V13版本,以前是V12,因為我Email帳號是沒繳費的帳號,所以是不能用正式的API來調試Service的。儲值後Google會先扣掉50塊,不明所以!

如在項目中分別引用兩類API:

  • 正式API

  URL:https://adwords.google.com/api/adwords/v13/AccountService?wsdl

  引用命名:GoogleAdwords.AccountService

  • 測試API

  URL:https://sandbox.google.com/api/adwords/v13/AccountService?wsdl

  引用命名:GoogleAdwords.Sandbox.AccountService

代碼如下,分別測試時就會有如下錯誤:

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web;

//正式API
using GAE.CL.GoogleAdwords.AccountService;
//測試API
//using GAE.CL.GoogleAdwords.Sandbox.AccountService;

namespace GAE.CL.ClassLibrary
{
    public class Main
    {
        #region 常量
        private static string email = "itblackhole@gmail.com";
        private static string password = "******";
        private static string useragent = "INSERT_COMPANY_NAME: AdWords API DotNet Sample Code";
        private static string developerToken = "itblackhole@gmail.com++CNY";
        private static string applicationToken = "INSERT_APPLICATION_TOKEN_HERE";
        #endregion 常量

        public void getClientAccounts(out string[] customerClientEmail)
        {
            customerClientEmail = null;
            try
            {
                // Set up service connection.
                AccountService service = new AccountService();

                // Define SOAP headers.
                service.emailValue = new email();
                service.emailValue.Text = new String[] { email };
                service.passwordValue = new password();
                service.passwordValue.Text = new String[] { password };
                service.useragentValue = new useragent();
                service.useragentValue.Text = new String[] { useragent };
                service.developerTokenValue = new developerToken();
                service.developerTokenValue.Text = new String[] { developerToken };
                service.applicationTokenValue = new applicationToken();
                service.applicationTokenValue.Text = new String[] { applicationToken };

                // Get client accounts.
                string[] loginEmails = service.getClientAccounts();

                // Display login emails.
                if (loginEmails != null)
                {
                    customerClientEmail = loginEmails;
                    foreach (string customerEmail in loginEmails)
                    {
                        HttpContext.Current.Response.Write("Login email is  \"" + customerEmail + "\".<br/>");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("當“我的客戶中心”(MCC) 帳戶修改客戶帳戶時要使用的標題元素。<br/>");
                }

            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Write(e.ToString() + "<br/>");
            }
        }
    }
}

 

如果使用正式的API運行上面的代碼,就會報“無效的開發人員令牌”,如:System.Web.Services.Protocols.SoapException: The developer token is invalid.

如果使用測試的API運行,則會正確的返回如下資訊:

Login email is "client_1+itblackhole@gmail.com".
Login email is "client_2+itblackhole@gmail.com".
Login email is "client_3+itblackhole@gmail.com".
Login email is "client_4+itblackhole@gmail.com".
Login email is "client_5+itblackhole@gmail.com".

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.