Subversion Repositories SmartDukaan

Rev

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

Rev 9005 Rev 9227
Line 37... Line 37...
37
 *
37
 *
38
 * @author Kevin Winter
38
 * @author Kevin Winter
39
 */
39
 */
40
public class PauseAd {
40
public class PauseAd {
41
 
41
 
42
  public static void main(String[] args) throws Exception {
42
	public static Long runExample(Long adGroupId, Long adId)
-
 
43
	throws Exception {
43
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
44
		// Generate a refreshable OAuth2 credential similar to a ClientLogin token
44
    // and can be used in place of a service account.
45
		// and can be used in place of a service account.
45
    Credential oAuth2Credential = new OfflineCredentials.Builder()
46
		Credential oAuth2Credential = new OfflineCredentials.Builder()
46
        .forApi(Api.ADWORDS)
47
		.forApi(Api.ADWORDS)
47
        .fromFile()
48
		.fromFile()
48
        .build()
49
		.build()
49
        .generateCredential();
50
		.generateCredential();
50
 
51
 
51
    // Construct an AdWordsSession.
52
		// Construct an AdWordsSession.
52
    AdWordsSession session = new AdWordsSession.Builder()
53
		AdWordsSession session = new AdWordsSession.Builder()
53
        .fromFile()
54
		.fromFile()
54
        .withOAuth2Credential(oAuth2Credential)
55
		.withOAuth2Credential(oAuth2Credential)
55
        .build();
56
		.build();
56
 
-
 
57
    long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
-
 
58
    long adId = Long.parseLong("INSERT_AD_ID_HERE");
-
 
59
 
57
 
60
    AdWordsServices adWordsServices = new AdWordsServices();
58
		AdWordsServices adWordsServices = new AdWordsServices();
61
 
-
 
62
    runExample(adWordsServices, session, adGroupId, adId);
-
 
63
  }
-
 
64
 
59
 
65
  public static void runExample(
-
 
66
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId, Long adId)
-
 
67
      throws Exception {
-
 
68
    // Get the AdGroupAdService.
60
		// Get the AdGroupAdService.
69
    AdGroupAdServiceInterface adGroupAdService =
61
		AdGroupAdServiceInterface adGroupAdService =
70
        adWordsServices.get(session, AdGroupAdServiceInterface.class);
62
			adWordsServices.get(session, AdGroupAdServiceInterface.class);
71
 
63
 
72
    // Create ad with updated status.
64
		// Create ad with updated status.
73
    Ad ad = new Ad();
65
		Ad ad = new Ad();
74
    ad.setId(adId);
66
		ad.setId(adId);
75
    
67
 
76
    AdGroupAd adGroupAd = new AdGroupAd();
68
		AdGroupAd adGroupAd = new AdGroupAd();
77
    adGroupAd.setAdGroupId(adGroupId);
69
		adGroupAd.setAdGroupId(adGroupId);
78
    adGroupAd.setAd(ad);
70
		adGroupAd.setAd(ad);
79
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
71
		adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
80
 
72
 
81
    // Create operations.
73
		// Create operations.
82
    AdGroupAdOperation operation = new AdGroupAdOperation();
74
		AdGroupAdOperation operation = new AdGroupAdOperation();
83
    operation.setOperand(adGroupAd);
75
		operation.setOperand(adGroupAd);
84
    operation.setOperator(Operator.SET);
76
		operation.setOperator(Operator.SET);
85
 
77
 
86
    AdGroupAdOperation[] operations = new AdGroupAdOperation[] {operation};
78
		AdGroupAdOperation[] operations = new AdGroupAdOperation[] {operation};
87
 
79
 
88
    // Update ad.
80
		// Update ad.
89
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
81
		AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
90
 
82
		
-
 
83
		Long updatedAdId = 0l;
91
    // Display ads.
84
		// Display ads.
92
    for (AdGroupAd adGroupAdResult : result.getValue()) {
85
		for (AdGroupAd adGroupAdResult : result.getValue()) {
93
      System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\", type \""
86
			System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\", type \""
94
          + adGroupAdResult.getAd().getAdType() + "\", and status \"" + adGroupAdResult.getStatus()
87
					+ adGroupAdResult.getAd().getAdType() + "\", and status \"" + adGroupAdResult.getStatus()
95
          + "\" was updated.");
88
					+ "\" was updated.");
-
 
89
			updatedAdId = adGroupAdResult.getAd().getId();
96
    }
90
		}
-
 
91
		
-
 
92
		return updatedAdId;
97
  }
93
	}
98
}
94
}