Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9005 manish.sha 1
// Copyright 2013 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.v201302.adwordsforvideo;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201302.cm.Operator;
19
import com.google.api.ads.adwords.axis.v201302.video.CallToAction;
20
import com.google.api.ads.adwords.axis.v201302.video.CallToActionCreative;
21
import com.google.api.ads.adwords.axis.v201302.video.VideoCallToAction;
22
import com.google.api.ads.adwords.axis.v201302.video.VideoCallToActionOperation;
23
import com.google.api.ads.adwords.axis.v201302.video.VideoReturnValue;
24
import com.google.api.ads.adwords.axis.v201302.video.VideoServiceInterface;
25
import com.google.api.ads.adwords.axis.v201302.video.YouTubeVideo;
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 illustrates how to create a video call to action overlay.
33
 *
34
 * Credentials and properties in {@code fromFile()} are pulled from the
35
 * "ads.properties" file. See README for more info.
36
 *
37
 * Tags: VideoService.mutate
38
 *
39
 * Category: adx-exclude
40
 *
41
 * @author Takeshi Hagikura
42
 */
43
public class AddVideoCallToAction {
44
 
45
  public static void main(String[] args) throws Exception {
46
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
47
    // and can be used in place of a service account.
48
    Credential oAuth2Credential = new OfflineCredentials.Builder()
49
        .forApi(Api.ADWORDS)
50
        .fromFile()
51
        .build()
52
        .generateCredential();
53
 
54
    // Construct an AdWordsSession.
55
    AdWordsSession session = new AdWordsSession.Builder()
56
        .fromFile()
57
        .withOAuth2Credential(oAuth2Credential)
58
        .build();
59
 
60
    AdWordsServices adWordsServices = new AdWordsServices();
61
 
62
    String videoId = "INSERT_VIDEO_ID_HERE";
63
 
64
    runExample(adWordsServices, session, videoId);
65
  }
66
 
67
  public static void runExample(
68
      AdWordsServices adWordsServices, AdWordsSession session, String videoId) throws Exception {
69
 
70
    // Get the VideoService.
71
    VideoServiceInterface videoService =
72
        adWordsServices.get(session, VideoServiceInterface.class);
73
 
74
    VideoCallToAction videoCallToAction = new VideoCallToAction();
75
    videoCallToAction.setId(videoId);
76
    CallToAction callToAction = new CallToAction();
77
    CallToActionCreative callToActionCreative = new CallToActionCreative();
78
    callToActionCreative.setHeadline("Mars cruise");
79
    callToActionCreative.setDescriptionLine1("Astonishing views");
80
    callToActionCreative.setDescriptionLine2("Mild climate");
81
    callToActionCreative.setDisplayUrl("www.example.com/mars");
82
    callToActionCreative.setDestinationUrl("www.example.com/mars");
83
    callToAction.setCreative(callToActionCreative);
84
    videoCallToAction.setCallToAction(callToAction);
85
 
86
    VideoCallToActionOperation operation = new VideoCallToActionOperation();
87
    operation.setOperand(videoCallToAction);
88
    operation.setOperator(Operator.ADD);
89
 
90
    VideoCallToActionOperation[] operations = new VideoCallToActionOperation[] {operation};
91
 
92
    // Add video call to action.
93
    VideoReturnValue result = videoService.mutateCallToAction(operations);
94
 
95
    if (result != null && result.getValue() != null) {
96
      for (YouTubeVideo youTubeVideo : result.getValue()) {
97
        System.out.println("CallToAction overlay was added to video ID \""
98
            + youTubeVideo.getId() + "\",  headline \""
99
            + youTubeVideo.getCallToAction().getCreative().getHeadline() + "\" .");
100
      }
101
    } else {
102
      System.out.println("No call to action overlays were added.");
103
    }
104
  }
105
}