I am working on automating the upload of video assets to the Google Ads asset library. The process involves first uploading the video to YouTube via the YouTube Data API and then attaching the uploaded video's ID to Google Ads using the Google Ads API.

Here’s a snippet of the code I'm using to upload a video to YouTube:

public void upload(Credential credential) throws Exception {     YouTube youtubeService = new YouTube.Builder(         new NetHttpTransport(), JacksonFactory.getDefaultInstance(), credential)         .setApplicationName("youtube-upload")         .build();     File initialFile = new File("src/main/resources/test.mp4");     InputStream targetStream = new FileInputStream(initialFile);     InputStreamContent mediaContent = new InputStreamContent("video/*", targetStream);     Video videoObjectDefiningMetadata = new Video();     VideoSnippet snippet = new VideoSnippet();     snippet.setTitle("Test Video " + System.currentTimeMillis());     snippet.setDescription("A video uploaded via YouTube API");     snippet.setTags(Arrays.asList("test", "video", "upload"));     VideoStatus status = new VideoStatus();     status.setPrivacyStatus("private");     videoObjectDefiningMetadata.setSnippet(snippet);     videoObjectDefiningMetadata.setStatus(status);     YouTube.Videos.Insert videoInsert = youtubeService.videos()         .insert(List.of("snippet", "statistics", "status"), videoObjectDefiningMetadata, mediaContent);     Video returnedVideo = videoInsert.execute();     System.out.println("Uploaded video ID: " + returnedVideo.getId());     adsService.uploadVideo(returnedVideo); } 

The code works as expected and uploads the video to YouTube, retrieves the video ID, and uses it for Google Ads. However, I am hitting YouTube API upload quotas pretty quickly, and this is causing problems for scaling this process.

My Question:

How can I handle or mitigate YouTube API quota limits when uploading videos in bulk? Is there a way to optimize or reduce the number of quota points consumed when uploading videos via the API? Are there any alternative approaches or best practices to avoid hitting the quota limit?

Notes:

I am already following YouTube’s best practices for uploads (setting the video privacy to “private,” limiting tags, etc.), but the quota usage is still significant. The YouTube API quota system allocates 1600 units per day for each project by default. Each video upload request consumes around 1600 units (as per the documentation).

Relevant API Documentation:

  1. YouTube Data API
  2. Google Ads API
  3. Youtube Support Post

Tag:google-ads-api, java, youtube-api, youtube-data-api

Add a new comment.