Subversion Repositories SmartDukaan

Rev

Rev 9005 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9005 Rev 9018
Line 50... Line 50...
50
 * Category: adx-exclude
50
 * Category: adx-exclude
51
 *
51
 *
52
 * @author Kevin Winter
52
 * @author Kevin Winter
53
 */
53
 */
54
public class GetKeywords {
54
public class GetKeywords {
55
/* 6796860944 |
-
 
56
| 6796861064 |
-
 
57
| 6796861184 |
-
 
58
| 6796861304 |
-
 
59
| 6796861424 |
-
 
60
| 6796861544 |
-
 
61
| 6803931224 |
-
 
62
| 6803931344 |
-
 
63
| 6803931464 |
-
 
64
| 6803931584 |
-
 
65
| 6803931704 |
-
 
66
| 4438409624 |
-
 
67
| 4439752304 |
-
 
68
| 4439752424 |
-
 
69
	*/
55
 
70
	private static final int PAGE_SIZE = 100;
56
	private static final int PAGE_SIZE = 100;
71
	
57
	
72
	public static void main(String[] args) {
58
	public static void main(String[] args) {
73
		try {
59
		try {
74
			List<Long> adgroupIds=new ArrayList<Long>();
-
 
75
			adgroupIds.add(6796860944L);
-
 
76
			adgroupIds.add(6796861064L);
-
 
77
			adgroupIds.add(6796861184L);
-
 
78
			adgroupIds.add(6796861304L);
60
			runExample(6796861424L);
79
			for(Long adgroupId : adgroupIds){
-
 
80
				List<Map<String, String>> adgroupAdKeywordDataMainList = runExample(adgroupId);
-
 
81
				if(adgroupAdKeywordDataMainList.size()>0){
-
 
82
					for(Map<String,String> adgroupAdKeywordDataMap : adgroupAdKeywordDataMainList){
-
 
83
						System.out.println(adgroupAdKeywordDataMap.get("AdgroupId")+" "
-
 
84
								+adgroupAdKeywordDataMap.get("Text")+" "
-
 
85
								+adgroupAdKeywordDataMap.get("CriterionId")+ " "
-
 
86
								+adgroupAdKeywordDataMap.get("Type")+" "
-
 
87
								+adgroupAdKeywordDataMap.get("BidAmount"));
-
 
88
					}
-
 
89
				}
-
 
90
			}
-
 
91
		} catch (Exception e) {
61
		} catch (Exception e) {
92
			// TODO Auto-generated catch block
-
 
93
			e.printStackTrace();
62
			e.printStackTrace();
94
		}
63
		}
95
	}
64
	}
96
 
65
 
97
	public static List<Map<String, String>> runExample(Long adGroupId) throws Exception {
66
	public static List<Map<String, String>> runExample(Long adGroupId) throws Exception {
Line 118... Line 87...
118
		int offset = 0;
87
		int offset = 0;
119
		boolean morePages = true;
88
		boolean morePages = true;
120
 
89
 
121
		// Create selector.
90
		// Create selector.
122
		Selector selector = new Selector();
91
		Selector selector = new Selector();
123
		selector.setFields(new String[] {"Id", "AdGroupId", "MatchType", "KeywordText"});
92
		selector.setFields(new String[] {"Id", "AdGroupId", "CpcBid" ,"MatchType","KeywordText"});
124
		selector.setOrdering(new OrderBy[] {new OrderBy("AdGroupId", SortOrder.ASCENDING)});
93
		selector.setOrdering(new OrderBy[] {new OrderBy("AdGroupId", SortOrder.ASCENDING)});
125
		selector.setPaging(new Paging(offset, PAGE_SIZE));
94
		selector.setPaging(new Paging(offset, PAGE_SIZE));
126
 
95
 
127
		// Create predicates.
96
		// Create predicates.
128
		Predicate adGroupIdPredicate =
97
		Predicate adGroupIdPredicate =
Line 144... Line 113...
144
					System.out.println("Keyword ad group criterion with ad group id \""
113
					System.out.println("Keyword ad group criterion with ad group id \""
145
							+ adGroupCriterionResult.getAdGroupId() + "\", criterion id \""
114
							+ adGroupCriterionResult.getAdGroupId() + "\", criterion id \""
146
							+ adGroupCriterionResult.getCriterion().getId() + "\", text \""
115
							+ adGroupCriterionResult.getCriterion().getId() + "\", text \""
147
							+ ((Keyword) adGroupCriterionResult.getCriterion()).getText()
116
							+ ((Keyword) adGroupCriterionResult.getCriterion()).getText()
148
							+ "\" and match type \""
117
							+ "\" and match type \""
149
							+ ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType() + "\" was found.");
118
							+ ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType() 
150
					
119
							+ " was found.");
151
						BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
120
					BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
-
 
121
					if(("Keyword").equalsIgnoreCase(adGroupCriterionResult.getCriterion().getCriterionType())){
152
						Keyword keyword = (Keyword) adGroupCriterionResult.getCriterion();
122
						Keyword keyword = (Keyword) adGroupCriterionResult.getCriterion();
153
						if(biddableAdGroupCriterion!=null){
123
						if(biddableAdGroupCriterion.getBiddingStrategyConfiguration()!=null){
154
							if(biddableAdGroupCriterion.getBiddingStrategyConfiguration()!=null){
124
							if(("CpcBid").equalsIgnoreCase(biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids(0).getBidsType())){
155
								Bids bid = biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids(0);
125
								CpcBid bid = (CpcBid)biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids(0);
156
							
-
 
157
								Map<String,String> keywordMap = new HashMap<String,String>();
126
								Map<String,String> keywordMap = new HashMap<String,String>();
158
								keywordMap.put("AdgroupId", adGroupCriterionResult.getAdGroupId()+"");
127
								keywordMap.put("AdgroupId", adGroupCriterionResult.getAdGroupId()+"");
159
								keywordMap.put("Text",keyword.getText());
128
								keywordMap.put("Text",keyword.getText());
160
								keywordMap.put("CriterionId", keyword.getId()+"");
129
								keywordMap.put("CriterionId", keyword.getId()+"");
161
								keywordMap.put("Type", keyword.getMatchType().getValue());
130
								keywordMap.put("Type", keyword.getMatchType().getValue());
162
								keywordMap.put("BidAmount", ((CpcBid)bid).getBid().getMicroAmount()+"");
131
								keywordMap.put("BidAmount", bid.getBid().getMicroAmount()+"");
163
								keywordDataMainList.add(keywordMap);
132
								keywordDataMainList.add(keywordMap);
164
							
-
 
165
							}
133
							}
-
 
134
						}
166
					}
135
					}
-
 
136
						
167
				}
137
				}
168
			} else {
138
			} else {
169
				System.out.println("No ad group criteria were found.");
139
				System.out.println("No ad group criteria were found.");
170
			}
140
			}
171
 
141
 
172
			offset += PAGE_SIZE;
142
			offset += PAGE_SIZE;
173
			selector.getPaging().setStartIndex(offset);
143
			selector.getPaging().setStartIndex(offset);
174
			morePages = offset < page.getTotalNumEntries();
144
			morePages = offset < page.getTotalNumEntries();
175
		}
145
		}
-
 
146
		
-
 
147
		for(Map<String,String> adgroupAdKeywordDataMap : keywordDataMainList){
-
 
148
			System.out.println(adgroupAdKeywordDataMap.get("AdgroupId")+" "
-
 
149
					+adgroupAdKeywordDataMap.get("Text")+" "
-
 
150
					+adgroupAdKeywordDataMap.get("CriterionId")+ " "
-
 
151
					+adgroupAdKeywordDataMap.get("Type")+" "
-
 
152
					+adgroupAdKeywordDataMap.get("BidAmount"));
-
 
153
		}
176
		return keywordDataMainList;
154
		return keywordDataMainList;
177
	}
155
	}
178
}
156
}