Subversion Repositories SmartDukaan

Rev

Rev 9005 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9005 manish.sha 1
// Copyright 2012 Google Inc. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
package adwords.axis.v201309.basicoperations;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201309.cm.Ad;
19
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupAd;
20
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupAdOperation;
21
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupAdReturnValue;
22
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupAdServiceInterface;
23
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupAdStatus;
24
import com.google.api.ads.adwords.axis.v201309.cm.Operator;
25
import com.google.api.ads.adwords.lib.client.AdWordsSession;
26
import com.google.api.ads.common.lib.auth.OfflineCredentials;
27
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
28
import com.google.api.client.auth.oauth2.Credential;
29
 
30
/**
31
 * This example updates status for a given ad. To get ads, run GetTextAds.
32
 *
33
 * Credentials and properties in {@code fromFile()} are pulled from the
34
 * "ads.properties" file. See README for more info.
35
 *
36
 * Tags: AdGroupAdService.mutate
37
 *
38
 * @author Kevin Winter
39
 */
40
public class PauseAd {
41
 
9227 manish.sha 42
	public static Long runExample(Long adGroupId, Long adId)
43
	throws Exception {
44
		// Generate a refreshable OAuth2 credential similar to a ClientLogin token
45
		// and can be used in place of a service account.
46
		Credential oAuth2Credential = new OfflineCredentials.Builder()
47
		.forApi(Api.ADWORDS)
48
		.fromFile()
49
		.build()
50
		.generateCredential();
9005 manish.sha 51
 
9227 manish.sha 52
		// Construct an AdWordsSession.
53
		AdWordsSession session = new AdWordsSession.Builder()
54
		.fromFile()
55
		.withOAuth2Credential(oAuth2Credential)
56
		.build();
9005 manish.sha 57
 
9227 manish.sha 58
		AdWordsServices adWordsServices = new AdWordsServices();
9005 manish.sha 59
 
9227 manish.sha 60
		// Get the AdGroupAdService.
61
		AdGroupAdServiceInterface adGroupAdService =
62
			adWordsServices.get(session, AdGroupAdServiceInterface.class);
9005 manish.sha 63
 
9227 manish.sha 64
		// Create ad with updated status.
65
		Ad ad = new Ad();
66
		ad.setId(adId);
9005 manish.sha 67
 
9227 manish.sha 68
		AdGroupAd adGroupAd = new AdGroupAd();
69
		adGroupAd.setAdGroupId(adGroupId);
70
		adGroupAd.setAd(ad);
71
		adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
9005 manish.sha 72
 
9227 manish.sha 73
		// Create operations.
74
		AdGroupAdOperation operation = new AdGroupAdOperation();
75
		operation.setOperand(adGroupAd);
76
		operation.setOperator(Operator.SET);
9005 manish.sha 77
 
9227 manish.sha 78
		AdGroupAdOperation[] operations = new AdGroupAdOperation[] {operation};
9005 manish.sha 79
 
9227 manish.sha 80
		// Update ad.
81
		AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
82
 
83
		Long updatedAdId = 0l;
84
		// Display ads.
85
		for (AdGroupAd adGroupAdResult : result.getValue()) {
86
			System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\", type \""
87
					+ adGroupAdResult.getAd().getAdType() + "\", and status \"" + adGroupAdResult.getStatus()
88
					+ "\" was updated.");
89
			updatedAdId = adGroupAdResult.getAd().getId();
90
		}
91
 
92
		return updatedAdId;
93
	}
9005 manish.sha 94
}