Subversion Repositories SmartDukaan

Rev

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.v201306.basicoperations;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201306.cm.Campaign;
19
import com.google.api.ads.adwords.axis.v201306.cm.CampaignOperation;
20
import com.google.api.ads.adwords.axis.v201306.cm.CampaignReturnValue;
21
import com.google.api.ads.adwords.axis.v201306.cm.CampaignServiceInterface;
22
import com.google.api.ads.adwords.axis.v201306.cm.CampaignStatus;
23
import com.google.api.ads.adwords.axis.v201306.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
import java.text.SimpleDateFormat;
30
import java.util.Date;
31
 
32
/**
33
 * This example deletes a campaign by setting the status to 'DELETED'. To get
34
 * campaigns, run GetCampaigns.java.
35
 *
36
 * Credentials and properties in {@code fromFile()} are pulled from the
37
 * "ads.properties" file. See README for more info.
38
 *
39
 * Tags: CampaignService.mutate
40
 *
41
 * @author Kevin Winter
42
 */
43
public class DeleteCampaign {
44
 
45
  public static void main(String[] args) throws Exception {
46
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
47
    // and can be used in place of a service account.
48
    Credential oAuth2Credential = new OfflineCredentials.Builder()
49
        .forApi(Api.ADWORDS)
50
        .fromFile()
51
        .build()
52
        .generateCredential();
53
 
54
    // Construct an AdWordsSession.
55
    AdWordsSession session = new AdWordsSession.Builder()
56
        .fromFile()
57
        .withOAuth2Credential(oAuth2Credential)
58
        .build();
59
 
60
    long campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
61
 
62
    AdWordsServices adWordsServices = new AdWordsServices();
63
 
64
    runExample(adWordsServices, session, campaignId);
65
  }
66
 
67
  public static void runExample(
68
      AdWordsServices adWordsServices, AdWordsSession session, long campaignId) throws Exception {
69
    // Get the CampaignService.
70
    CampaignServiceInterface campaignService =
71
        adWordsServices.get(session, CampaignServiceInterface.class);
72
 
73
    // Create campaign with DELETED status.
74
    Campaign campaign = new Campaign();
75
    campaign.setId(campaignId);
76
    campaign.setStatus(CampaignStatus.DELETED);
77
    // We recommend including the original name when renaming before delete.
78
    campaign.setName("Deleted on " + new SimpleDateFormat("yyMMDD HH:mm:ss.S").format(new Date()));
79
 
80
    // Create operations.
81
    CampaignOperation operation = new CampaignOperation();
82
    operation.setOperand(campaign);
83
    operation.setOperator(Operator.SET);
84
 
85
    CampaignOperation[] operations = new CampaignOperation[] {operation};
86
 
87
    // Delete campaign.
88
    CampaignReturnValue result = campaignService.mutate(operations);
89
 
90
    // Display campaigns.
91
    for (Campaign campaignResult : result.getValue()) {
92
      System.out.println("Campaign with name \"" + campaignResult.getName() + "\" and id \""
93
          + campaignResult.getId() + "\" was deleted.");
94
    }
95
  }
96
}