Google Adwords API

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

代码如下,分别测试时就会有如下错误:

ContractedBlock.gif ExpandedBlockStart.gif 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".

 

转载于:https://www.cnblogs.com/blackcore/archive/2009/10/23/1588591.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值