Google adwords APIs are divided into formal APIs and test APIs.
Official APIs in the base layer are charged, and Google charges fees based on the API unit. In the test API (sandbox), no fees are charged, but some APIs return results defined by Google, not a good test! Google is also the recently released v13 version. It used to be V12. Because my email account is a non-paid account, you cannot use the official API to debug the service. After recharge, Google will deduct 50 items first!
For example, two types of APIs are referenced in a project:
URL: https://adwords.google.com/api/adwords/v13/AccountService? WSDL
Reference name: googleadwords. accountservice
URL: https://sandbox.google.com/api/adwords/v13/AccountService? WSDL
Reference name: googleadwords. sandbox. accountservice
CodeAs shown in the following figure, the following errors will occur during the test respectively:
Code
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
UsingSystem. Web;
// Formal API
Using Gae. Cl. googleadwords. accountservice;
// Test API
// Using Gae. Cl. googleadwords. sandbox. accountservice;
Namespace Gae. Cl. classlibrary
{
Public Class Main
{
# Region Constant
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 Token token = " Itblackhole@gmail.com ++ CNY " ;
Private Static String Applicationtoken = " Insert_application_token_here " ;
# Endregion Constant
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. Define tokenvalue = New Token token ();
Service. Define tokenvalue. Text = New String [] {token };
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 ( " Header element to be used when the "my customer center" (MCC) account modifies the customer account. <Br/> " );
}
}
Catch(Exception E)
{
Httpcontext. Current. response. Write (E. tostring ()+ "<Br/>");
}
}
}
}
If you use a formal API to run the above Code, an "invalid developer token" will be reported, for example, system. Web. Services. Protocols. soapexception: The developer token is invalid.
If you run the test API, the following information is returned correctly:
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 ".