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.campaignmanagement;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201306.cm.AdGroupAd;
19
import com.google.api.ads.adwords.axis.v201306.cm.AdGroupAdPage;
20
import com.google.api.ads.adwords.axis.v201306.cm.AdGroupAdServiceInterface;
21
import com.google.api.ads.adwords.axis.v201306.cm.OrderBy;
22
import com.google.api.ads.adwords.axis.v201306.cm.Predicate;
23
import com.google.api.ads.adwords.axis.v201306.cm.PredicateOperator;
24
import com.google.api.ads.adwords.axis.v201306.cm.Selector;
25
import com.google.api.ads.adwords.axis.v201306.cm.SortOrder;
26
import com.google.api.ads.adwords.lib.client.AdWordsSession;
27
import com.google.api.ads.common.lib.auth.OfflineCredentials;
28
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
29
import com.google.api.client.auth.oauth2.Credential;
30
 
31
/**
32
 * This example gets all disapproved ads in an ad group. To add ads, run
33
 * AddTextAds.java. To get ad groups, run GetAdGroups.java.
34
 *
35
 * Credentials and properties in {@code fromFile()} are pulled from the
36
 * "ads.properties" file. See README for more info.
37
 *
38
 * Tags: AdGroupAdService.get
39
 *
40
 * @author Kevin Winter
41
 */
42
public class GetAllDisapprovedAds {
43
 
44
  public static void main(String[] args) throws Exception {
45
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
46
    // and can be used in place of a service account.
47
    Credential oAuth2Credential = new OfflineCredentials.Builder()
48
        .forApi(Api.ADWORDS)
49
        .fromFile()
50
        .build()
51
        .generateCredential();
52
 
53
    // Construct an AdWordsSession.
54
    AdWordsSession session = new AdWordsSession.Builder()
55
        .fromFile()
56
        .withOAuth2Credential(oAuth2Credential)
57
        .build();
58
 
59
    long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
60
 
61
    AdWordsServices adWordsServices = new AdWordsServices();
62
 
63
    runExample(adWordsServices, session, adGroupId);
64
  }
65
 
66
  public static void runExample(
67
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
68
    // Get the AdGroupAdService.
69
    AdGroupAdServiceInterface adGroupAdService =
70
        adWordsServices.get(session, AdGroupAdServiceInterface.class);
71
 
72
    // Create selector.
73
    Selector selector = new Selector();
74
    selector.setFields(new String[] {"Id", "DisapprovalReasons"});
75
    selector.setOrdering(new OrderBy[] {new OrderBy("Id", SortOrder.ASCENDING)});
76
 
77
    // Create predicates.
78
    Predicate adGroupIdPredicate =
79
        new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
80
    Predicate approvalStatusPredicate = new Predicate(
81
        "AdGroupCreativeApprovalStatus", PredicateOperator.IN, new String[] {"DISAPPROVED"});
82
    selector.setPredicates(new Predicate[] {adGroupIdPredicate, approvalStatusPredicate});
83
 
84
    // Get all disapproved ads.
85
    AdGroupAdPage page = adGroupAdService.get(selector);
86
 
87
    // Display ads.
88
    if (page.getEntries() != null && page.getEntries().length > 0) {
89
      for (AdGroupAd adGroupAd : page.getEntries()) {
90
        System.out.println("Ad with id \"" + adGroupAd.getAd().getId() + "\"" + " and type \""
91
            + adGroupAd.getAd().getAdType() + "\" was disapproved for the following reasons:");
92
        for (String reason : adGroupAd.getAd().getDisapprovalReasons()) {
93
          System.out.println("  \"" + reason + "\"");
94
        }
95
      }
96
    } else {
97
      System.out.println("No ads were found.");
98
    }
99
  }
100
}