| Line 12... |
Line 12... |
| 12 |
// See the License for the specific language governing permissions and
|
12 |
// See the License for the specific language governing permissions and
|
| 13 |
// limitations under the License.
|
13 |
// limitations under the License.
|
| 14 |
|
14 |
|
| 15 |
package adwords.axis.v201309.basicoperations;
|
15 |
package adwords.axis.v201309.basicoperations;
|
| 16 |
|
16 |
|
| - |
|
17 |
import java.rmi.RemoteException;
|
| 17 |
import java.util.ArrayList;
|
18 |
import java.util.ArrayList;
|
| 18 |
import java.util.HashMap;
|
19 |
import java.util.HashMap;
|
| 19 |
import java.util.List;
|
20 |
import java.util.List;
|
| 20 |
import java.util.Map;
|
21 |
import java.util.Map;
|
| 21 |
|
22 |
|
| 22 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
23 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
| - |
|
24 |
import com.google.api.ads.adwords.axis.v201309.cm.ApiException;
|
| 23 |
import com.google.api.ads.adwords.axis.v201309.cm.Campaign;
|
25 |
import com.google.api.ads.adwords.axis.v201309.cm.Campaign;
|
| 24 |
import com.google.api.ads.adwords.axis.v201309.cm.CampaignPage;
|
26 |
import com.google.api.ads.adwords.axis.v201309.cm.CampaignPage;
|
| 25 |
import com.google.api.ads.adwords.axis.v201309.cm.CampaignServiceInterface;
|
27 |
import com.google.api.ads.adwords.axis.v201309.cm.CampaignServiceInterface;
|
| 26 |
import com.google.api.ads.adwords.axis.v201309.cm.OrderBy;
|
28 |
import com.google.api.ads.adwords.axis.v201309.cm.OrderBy;
|
| 27 |
import com.google.api.ads.adwords.axis.v201309.cm.Paging;
|
29 |
import com.google.api.ads.adwords.axis.v201309.cm.Paging;
|
| 28 |
import com.google.api.ads.adwords.axis.v201309.cm.Selector;
|
30 |
import com.google.api.ads.adwords.axis.v201309.cm.Selector;
|
| 29 |
import com.google.api.ads.adwords.axis.v201309.cm.SortOrder;
|
31 |
import com.google.api.ads.adwords.axis.v201309.cm.SortOrder;
|
| 30 |
import com.google.api.ads.adwords.lib.client.AdWordsSession;
|
32 |
import com.google.api.ads.adwords.lib.client.AdWordsSession;
|
| 31 |
import com.google.api.ads.common.lib.auth.OfflineCredentials;
|
33 |
import com.google.api.ads.common.lib.auth.OfflineCredentials;
|
| 32 |
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
|
34 |
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
|
| - |
|
35 |
import com.google.api.ads.common.lib.conf.ConfigurationLoadException;
|
| - |
|
36 |
import com.google.api.ads.common.lib.exception.OAuthException;
|
| - |
|
37 |
import com.google.api.ads.common.lib.exception.ValidationException;
|
| 33 |
import com.google.api.client.auth.oauth2.Credential;
|
38 |
import com.google.api.client.auth.oauth2.Credential;
|
| 34 |
|
39 |
|
| 35 |
/**
|
40 |
/**
|
| 36 |
* This example gets all campaigns. To add a campaign, run AddCampaign.java.
|
41 |
* This example gets all campaigns. To add a campaign, run AddCampaign.java.
|
| 37 |
*
|
42 |
*
|
| Line 53... |
Line 58... |
| 53 |
catch(Exception e){
|
58 |
catch(Exception e){
|
| 54 |
System.out.println(e.getMessage());
|
59 |
System.out.println(e.getMessage());
|
| 55 |
}
|
60 |
}
|
| 56 |
}
|
61 |
}
|
| 57 |
|
62 |
|
| 58 |
public static List<Map<String,String>> runExample() throws Exception {
|
63 |
public static List<Map<String,String>> runExample() {
|
| 59 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
64 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
| 60 |
// and can be used in place of a service account.
|
65 |
// and can be used in place of a service account.
|
| - |
|
66 |
Credential oAuth2Credential = null;
|
| - |
|
67 |
try {
|
| 61 |
Credential oAuth2Credential = new OfflineCredentials.Builder()
|
68 |
oAuth2Credential = new OfflineCredentials.Builder()
|
| 62 |
.forApi(Api.ADWORDS)
|
69 |
.forApi(Api.ADWORDS)
|
| 63 |
.fromFile()
|
70 |
.fromFile()
|
| 64 |
.build()
|
71 |
.build()
|
| 65 |
.generateCredential();
|
72 |
.generateCredential();
|
| - |
|
73 |
} catch (OAuthException e) {
|
| - |
|
74 |
// TODO Auto-generated catch block
|
| - |
|
75 |
e.printStackTrace();
|
| - |
|
76 |
} catch (ValidationException e) {
|
| - |
|
77 |
// TODO Auto-generated catch block
|
| - |
|
78 |
e.printStackTrace();
|
| - |
|
79 |
} catch (ConfigurationLoadException e) {
|
| - |
|
80 |
// TODO Auto-generated catch block
|
| - |
|
81 |
e.printStackTrace();
|
| - |
|
82 |
}
|
| 66 |
|
83 |
|
| 67 |
// Construct an AdWordsSession.
|
84 |
// Construct an AdWordsSession.
|
| - |
|
85 |
AdWordsSession session= null;
|
| - |
|
86 |
try {
|
| 68 |
AdWordsSession session = new AdWordsSession.Builder()
|
87 |
session = new AdWordsSession.Builder()
|
| 69 |
.fromFile()
|
88 |
.fromFile()
|
| 70 |
.withOAuth2Credential(oAuth2Credential)
|
89 |
.withOAuth2Credential(oAuth2Credential)
|
| 71 |
.build();
|
90 |
.build();
|
| - |
|
91 |
} catch (ValidationException e) {
|
| - |
|
92 |
// TODO Auto-generated catch block
|
| - |
|
93 |
e.printStackTrace();
|
| - |
|
94 |
} catch (ConfigurationLoadException e) {
|
| - |
|
95 |
// TODO Auto-generated catch block
|
| - |
|
96 |
e.printStackTrace();
|
| - |
|
97 |
}
|
| 72 |
|
98 |
|
| 73 |
AdWordsServices adWordsServices = new AdWordsServices();
|
99 |
AdWordsServices adWordsServices = new AdWordsServices();
|
| 74 |
|
100 |
|
| 75 |
// Get the CampaignService.
|
101 |
// Get the CampaignService.
|
| 76 |
CampaignServiceInterface campaignService =
|
102 |
CampaignServiceInterface campaignService =
|
| Line 85... |
Line 111... |
| 85 |
selector.setPaging(new Paging(offset, PAGE_SIZE));
|
111 |
selector.setPaging(new Paging(offset, PAGE_SIZE));
|
| 86 |
List<Map<String,String>> campaignDataMainList = new ArrayList<Map<String,String>>();
|
112 |
List<Map<String,String>> campaignDataMainList = new ArrayList<Map<String,String>>();
|
| 87 |
CampaignPage page = null;
|
113 |
CampaignPage page = null;
|
| 88 |
do {
|
114 |
do {
|
| 89 |
// Get all campaigns.
|
115 |
// Get all campaigns.
|
| - |
|
116 |
try {
|
| 90 |
page = campaignService.get(selector);
|
117 |
page = campaignService.get(selector);
|
| - |
|
118 |
} catch (ApiException e) {
|
| - |
|
119 |
// TODO Auto-generated catch block
|
| - |
|
120 |
e.printStackTrace();
|
| - |
|
121 |
} catch (RemoteException e) {
|
| - |
|
122 |
// TODO Auto-generated catch block
|
| - |
|
123 |
e.printStackTrace();
|
| - |
|
124 |
}
|
| 91 |
|
125 |
|
| 92 |
// Display campaigns.
|
126 |
// Display campaigns.
|
| 93 |
if (page.getEntries() != null) {
|
127 |
if (page.getEntries() != null) {
|
| 94 |
for (Campaign campaign : page.getEntries()) {
|
128 |
for (Campaign campaign : page.getEntries()) {
|
| 95 |
//if(campaign.getId() > 0l && campaign.getName()!=null && !("").equalsIgnoreCase(campaign.getName()) && campaign.getEndDate()!=null && !("").equalsIgnoreCase(campaign.getEndDate()) && campaign.getStartDate()!=null && !("").equalsIgnoreCase(campaign.getStartDate())){
|
129 |
//if(campaign.getId() > 0l && campaign.getName()!=null && !("").equalsIgnoreCase(campaign.getName()) && campaign.getEndDate()!=null && !("").equalsIgnoreCase(campaign.getEndDate()) && campaign.getStartDate()!=null && !("").equalsIgnoreCase(campaign.getStartDate())){
|