What's new? | Help | Directory | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2008, Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* This code sample creates a new text ad given an existing ad group. To create
* an ad group, you can run AddAdGroup.cs.
*/

using SampleCode.com.google.sandbox.v12.AdService;

using System;

public class AddTextAd {
// Provide AdWords login information.
private static String email = "INSERT_LOGIN_EMAIL_HERE";
private static String password = "INSERT_PASSWORD_HERE";
private static String clientEmail = "INSERT_CLIENT_LOGIN_EMAIL_HERE";
private static String useragent =
"INSERT_COMPANY_NAME: AdWords API DotNet Sample Code";
private static String developerToken = "INSERT_DEVELOPER_TOKEN_HERE";
private static String applicationToken =
"INSERT_APPLICATION_TOKEN_HERE";

public static void Main() {
try {
// Set up service connection.
AdService service = new AdService();

// Define SOAP headers.
service.emailValue = new email();
service.emailValue.Text = new String[] {email};
service.passwordValue = new password();
service.passwordValue.Text = new String[] {password};
service.clientEmailValue = new clientEmail();
service.clientEmailValue.Text = new String[] {clientEmail};
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};

// Create new text ad structure.
long adGroupId = long.Parse("INSERT_AD_GROUP_ID_HERE");

TextAd textAd = new TextAd();
textAd.adGroupId = adGroupId;
textAd.adType = AdType.TextAd;
textAd.adTypeSpecified = true;
textAd.headline = "Luxury Cruise to Mars";
textAd.description1 = "Visit the Red Planet in style.";
textAd.description2 = "Low-gravity fun for everyone!";
textAd.displayUrl = "www.example.com";
textAd.destinationUrl = "http://www.example.com";

// Check new ad for policy violations before adding it.
String[] languageTarget = {"en"};
GeoTarget geoTarget = new GeoTarget();
geoTarget.countryTargets = new String[] {"US"};
ApiError[] errors = service.checkAds(
new Ad[] {textAd}, languageTarget, geoTarget);

// Add text ad if there are no policy violations.
if (errors == null) {
Ad[] ads = service.addAds(new Ad[] {textAd});

// Display new text ad.
for (int i = 0; i < ads.Length; i++) {
textAd = (TextAd) ads[i];
Console.WriteLine("New text ad with headline \""
+ textAd.headline + "\" and id \"" + textAd.id
+ "\" was created.");
}
} else {
Console.WriteLine("New text ad was not created due to the following "
+ "policy violations:");
for (int i = 0; i < errors.Length; i++) {
Console.WriteLine(" Detail: " + errors[i].detail
+ " isExemptable: " + errors[i].isExemptable);
}
}
} catch (Exception e) {
Console.WriteLine(e);
}
}
}
Show details Hide details

Change log

r3 by api.arogal on Aug 12, 2008   Diff
Migrated all v11 files to v12 and removed
v11 refrences
Updated ChangeLog and README accordingly
Go to: 
Project members, sign in to write a code review

Older revisions

r2 by api.sgrinberg on Mar 11, 2008   Diff
Initial release of the AdWords API
DotNet Sample Code.
All revisions of this file

File info

Size: 3801 bytes, 97 lines