Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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.Campaign;
19
import com.google.api.ads.adwords.axis.v201309.cm.CampaignOperation;
20
import com.google.api.ads.adwords.axis.v201309.cm.CampaignReturnValue;
21
import com.google.api.ads.adwords.axis.v201309.cm.CampaignServiceInterface;
22
import com.google.api.ads.adwords.axis.v201309.cm.CampaignStatus;
23
import com.google.api.ads.adwords.axis.v201309.cm.Operator;
24
import com.google.api.ads.adwords.lib.client.AdWordsSession;
25
import com.google.api.ads.common.lib.auth.OfflineCredentials;
26
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
27
import com.google.api.client.auth.oauth2.Credential;
28
 
29
/**
30
 * This example updates a campaign by setting the status to PAUSED. To get
31
 * campaigns, run GetCampaigns.java.
32
 *
33
 * Credentials and properties in {@code fromFile()} are pulled from the
34
 * "ads.properties" file. See README for more info.
35
 *
36
 * Tags: CampaignService.mutate
37
 *
38
 * @author Kevin Winter
39
 */
40
public class UpdateCampaign {
41
 
42
	public static void main(String[] args) throws Exception {
43
		// Generate a refreshable OAuth2 credential similar to a ClientLogin token
44
		// and can be used in place of a service account.
45
		Credential oAuth2Credential = new OfflineCredentials.Builder()
46
		.forApi(Api.ADWORDS)
47
		.fromFile()
48
		.build()
49
		.generateCredential();
50
 
51
		// Construct an AdWordsSession.
52
		AdWordsSession session = new AdWordsSession.Builder()
53
		.fromFile()
54
		.withOAuth2Credential(oAuth2Credential)
55
		.build();
56
 
57
		long campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
58
 
59
		AdWordsServices adWordsServices = new AdWordsServices();
60
 
61
		runExample(adWordsServices, session, campaignId);
62
	}
63
 
64
	public static void runExample(
65
			AdWordsServices adWordsServices, AdWordsSession session, Long campaignId) throws Exception {
66
		// Get the CampaignService.
67
		CampaignServiceInterface campaignService =
68
			adWordsServices.get(session, CampaignServiceInterface.class);
69
 
70
		// Create campaign with updated status.
71
		Campaign campaign = new Campaign();
72
		campaign.setId(campaignId);
73
		campaign.setStatus(CampaignStatus.PAUSED);
74
 
75
 
76
		// Create operations.
77
		CampaignOperation operation = new CampaignOperation();
78
		operation.setOperand(campaign);
79
		operation.setOperator(Operator.SET);
80
 
81
		CampaignOperation[] operations = new CampaignOperation[] {operation};
82
 
83
		// Update campaign.
84
		CampaignReturnValue result = campaignService.mutate(operations);
85
 
86
		// Display campaigns.
87
		for (Campaign campaignResult : result.getValue()) {
88
			System.out.println("Campaign with name \"" + campaignResult.getName() + "\", id \""
89
					+ campaignResult.getId() + "\", and budget delivery method \""
90
					+ campaignResult.getBudget().getDeliveryMethod() + "\" was updated.");
91
		}
92
	}
93
}