Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9005 manish.sha 1
// Copyright 2013 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.v201302.campaignmanagement;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201302.cm.Campaign;
19
import com.google.api.ads.adwords.axis.v201302.cm.CampaignOperation;
20
import com.google.api.ads.adwords.axis.v201302.cm.CampaignReturnValue;
21
import com.google.api.ads.adwords.axis.v201302.cm.CampaignServiceInterface;
22
import com.google.api.ads.adwords.axis.v201302.cm.Operator;
23
import com.google.api.ads.adwords.lib.client.AdWordsSession;
24
import com.google.api.ads.common.lib.auth.OfflineCredentials;
25
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
26
import com.google.api.client.auth.oauth2.Credential;
27
 
28
/**
29
 * This example sets the enhanced bit in a given campaign.
30
 * To get campaigns, run basicoperations/GetCampaigns.java.
31
 *
32
 * Credentials and properties in {@code fromFile()} are pulled from the
33
 * "ads.properties" file. See README for more info.
34
 *
35
 * Tags: CampaignCriterionService.mutate
36
 *
37
 * @author Kevin Winter
38
 */
39
public class SetCampaignEnhanced {
40
 
41
  public static void main(String[] args) throws Exception {
42
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
43
    // and can be used in place of a service account.
44
    Credential oAuth2Credential = new OfflineCredentials.Builder()
45
        .forApi(Api.ADWORDS)
46
        .fromFile()
47
        .build()
48
        .generateCredential();
49
 
50
    // Construct an AdWordsSession.
51
    AdWordsSession session = new AdWordsSession.Builder()
52
        .fromFile()
53
        .withOAuth2Credential(oAuth2Credential)
54
        .build();
55
 
56
    Long campaignId = Long.valueOf("INSERT_CAMPAIGN_ID_HERE");
57
 
58
    AdWordsServices adWordsServices = new AdWordsServices();
59
 
60
    runExample(adWordsServices, session, campaignId);
61
  }
62
 
63
  public static void runExample(
64
      AdWordsServices adWordsServices, AdWordsSession session, Long campaignId) throws Exception {
65
    // Get the CampaignService.
66
    CampaignServiceInterface campaignService =
67
        adWordsServices.get(session, CampaignServiceInterface.class);
68
 
69
    // Campaign to be updated with the enhanced value.
70
    // Note: After setting the enhanced value to true, setting it back to false
71
    // will generate an ApiError.
72
    Campaign campaign = new Campaign();
73
    campaign.setId(campaignId);
74
    campaign.setEnhanced(true);
75
 
76
    // Create operation.
77
    CampaignOperation operation = new CampaignOperation();
78
    operation.setOperand(campaign);
79
    operation.setOperator(Operator.SET);
80
 
81
    // Change campaign.
82
    CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] {operation});
83
    for (Campaign campaignResult : result.getValue()) {
84
      System.out.printf("Campaign with ID %d has been set enhanced to '%s'.\n", campaign.getId(),
85
          campaign.getEnhanced());
86
    }
87
  }
88
}