Subversion Repositories SmartDukaan

Rev

Rev 9018 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9018 Rev 9441
Line 52... Line 52...
52
 * @author Kevin Winter
52
 * @author Kevin Winter
53
 */
53
 */
54
public class GetKeywords {
54
public class GetKeywords {
55
 
55
 
56
	private static final int PAGE_SIZE = 100;
56
	private static final int PAGE_SIZE = 100;
57
	
57
 
58
	public static void main(String[] args) {
58
	public static void main(String[] args) {
59
		try {
59
		try {
60
			runExample(6796861424L);
60
			runExample(6796861424L);
61
		} catch (Exception e) {
61
		} catch (Exception e) {
62
			e.printStackTrace();
62
			e.printStackTrace();
Line 77... Line 77...
77
		.fromFile()
77
		.fromFile()
78
		.withOAuth2Credential(oAuth2Credential)
78
		.withOAuth2Credential(oAuth2Credential)
79
		.build();
79
		.build();
80
 
80
 
81
		AdWordsServices adWordsServices = new AdWordsServices();
81
		AdWordsServices adWordsServices = new AdWordsServices();
82
		
82
 
83
		// Get the AdGroupCriterionService.
83
		// Get the AdGroupCriterionService.
84
		AdGroupCriterionServiceInterface adGroupCriterionService =
84
		AdGroupCriterionServiceInterface adGroupCriterionService =
85
			adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
85
			adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
86
 
86
 
87
		int offset = 0;
87
		int offset = 0;
Line 97... Line 97...
97
		Predicate adGroupIdPredicate =
97
		Predicate adGroupIdPredicate =
98
			new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
98
			new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
99
		Predicate criteriaTypePredicate =
99
		Predicate criteriaTypePredicate =
100
			new Predicate("CriteriaType", PredicateOperator.EQUALS, new String[] {"KEYWORD"});
100
			new Predicate("CriteriaType", PredicateOperator.EQUALS, new String[] {"KEYWORD"});
101
		selector.setPredicates(new Predicate[] {adGroupIdPredicate, criteriaTypePredicate});
101
		selector.setPredicates(new Predicate[] {adGroupIdPredicate, criteriaTypePredicate});
102
		
102
 
103
		List<Map<String, String>> keywordDataMainList = new ArrayList<Map<String,String>>();
103
		List<Map<String, String>> keywordDataMainList = new ArrayList<Map<String,String>>();
104
		
104
 
105
		while (morePages) {
105
		while (morePages) {
106
			// Get all ad group criteria.
106
			// Get all ad group criteria.
107
			AdGroupCriterionPage page = adGroupCriterionService.get(selector);
107
			AdGroupCriterionPage page = adGroupCriterionService.get(selector);
108
 
108
 
109
			// Display ad group criteria.
109
			// Display ad group criteria.
Line 119... Line 119...
119
							+ " was found.");
119
							+ " was found.");
120
					BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
120
					BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
121
					if(("Keyword").equalsIgnoreCase(adGroupCriterionResult.getCriterion().getCriterionType())){
121
					if(("Keyword").equalsIgnoreCase(adGroupCriterionResult.getCriterion().getCriterionType())){
122
						Keyword keyword = (Keyword) adGroupCriterionResult.getCriterion();
122
						Keyword keyword = (Keyword) adGroupCriterionResult.getCriterion();
123
						if(biddableAdGroupCriterion.getBiddingStrategyConfiguration()!=null){
123
						if(biddableAdGroupCriterion.getBiddingStrategyConfiguration()!=null){
124
							if(("CpcBid").equalsIgnoreCase(biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids(0).getBidsType())){
124
							Bids[] bids = biddableAdGroupCriterion.getBiddingStrategyConfiguration()
-
 
125
							.getBids();
-
 
126
							CpcBid cpcBid = null;
-
 
127
							for(Bids b: bids){
125
								CpcBid bid = (CpcBid)biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids(0);
128
								if("CpcBid".equalsIgnoreCase(b.getBidsType())){
-
 
129
									cpcBid = (CpcBid) b;
-
 
130
								}
-
 
131
							}
-
 
132
							if(cpcBid!=null){
126
								Map<String,String> keywordMap = new HashMap<String,String>();
133
								Map<String,String> keywordMap = new HashMap<String,String>();
127
								keywordMap.put("AdgroupId", adGroupCriterionResult.getAdGroupId()+"");
134
								keywordMap.put("AdgroupId", adGroupCriterionResult.getAdGroupId()+"");
128
								keywordMap.put("Text",keyword.getText());
135
								keywordMap.put("Text",keyword.getText());
129
								keywordMap.put("CriterionId", keyword.getId()+"");
136
								keywordMap.put("CriterionId", keyword.getId()+"");
130
								keywordMap.put("Type", keyword.getMatchType().getValue());
137
								keywordMap.put("Type", keyword.getMatchType().getValue());
131
								keywordMap.put("BidAmount", bid.getBid().getMicroAmount()+"");
138
								keywordMap.put("BidAmount", cpcBid.getBid().getMicroAmount()+"");
132
								keywordDataMainList.add(keywordMap);
139
								keywordDataMainList.add(keywordMap);
133
							}
140
							}
134
						}
141
						}
135
					}
142
					}
136
						
143
 
137
				}
144
				}
138
			} else {
145
			} else {
139
				System.out.println("No ad group criteria were found.");
146
				System.out.println("No ad group criteria were found.");
140
			}
147
			}
141
 
148
 
142
			offset += PAGE_SIZE;
149
			offset += PAGE_SIZE;
143
			selector.getPaging().setStartIndex(offset);
150
			selector.getPaging().setStartIndex(offset);
144
			morePages = offset < page.getTotalNumEntries();
151
			morePages = offset < page.getTotalNumEntries();
145
		}
152
		}
146
		
153
 
147
		for(Map<String,String> adgroupAdKeywordDataMap : keywordDataMainList){
154
		for(Map<String,String> adgroupAdKeywordDataMap : keywordDataMainList){
148
			System.out.println(adgroupAdKeywordDataMap.get("AdgroupId")+" "
155
			System.out.println(adgroupAdKeywordDataMap.get("AdgroupId")+" "
149
					+adgroupAdKeywordDataMap.get("Text")+" "
156
					+adgroupAdKeywordDataMap.get("Text")+" "
150
					+adgroupAdKeywordDataMap.get("CriterionId")+ " "
157
					+adgroupAdKeywordDataMap.get("CriterionId")+ " "
151
					+adgroupAdKeywordDataMap.get("Type")+" "
158
					+adgroupAdKeywordDataMap.get("Type")+" "