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.AdGroup;
19
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupOperation;
20
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupReturnValue;
21
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupServiceInterface;
22
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupStatus;
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 status for a given ad group. To get ad groups, run
31
 * GetAdGroups.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: AdGroupService.mutate
37
 *
38
 * @author Kevin Winter
39
 */
40
public class UpdateAdGroup {
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 adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
58
 
59
    AdWordsServices adWordsServices = new AdWordsServices();
60
 
61
    runExample(adWordsServices, session, adGroupId);
62
  }
63
 
64
  public static void runExample(
65
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
66
    // Get the AdGroupService.
67
    AdGroupServiceInterface adGroupService =
68
        adWordsServices.get(session, AdGroupServiceInterface.class);
69
 
70
    // Create ad group with updated status.
71
    AdGroup adGroup = new AdGroup();
72
    adGroup.setId(adGroupId);
73
    adGroup.setStatus(AdGroupStatus.PAUSED);
74
 
75
    // Create operations.
76
    AdGroupOperation operation = new AdGroupOperation();
77
    operation.setOperand(adGroup);
78
    operation.setOperator(Operator.SET);
79
 
80
    AdGroupOperation[] operations = new AdGroupOperation[] {operation};
81
 
82
    // Update ad group.
83
    AdGroupReturnValue result = adGroupService.mutate(operations);
84
 
85
    // Display ad groups.
86
    for (AdGroup adGroupResult : result.getValue()) {
87
      System.out.println("Ad group with name \"" + adGroupResult.getName() + "\", id \""
88
          + adGroupResult.getId() + "\", and status \"" + adGroupResult.getStatus()
89
          + "\" was updated.");
90
    }
91
  }
92
}