This shows how to upload a video using an HTTP request.

There are code snippets that are also available in java (and kotlin is pretty similar).

In order to see how to upload a video, go to https://developers.google.com/youtube/v3/code_samples/code_snippets, select Videos under Resource and insert under method.

If you then click on Show code and select JAVA at the top, you will get this example code:

/**
 * Sample Java code for youtube.videos.insert
 * See instructions for running these code samples locally:
 * https://developers.google.com/explorer-help/guides/code_samples#java
 */

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.InputStreamContent;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;

import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.Video;
import com.google.api.services.youtube.model.VideoSnippet;
import com.google.api.services.youtube.model.VideoStatus;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;

public class ApiExample {
    // You need to set this value for your code to compile.
    // For example: ... DEVELOPER_KEY = "YOUR ACTUAL KEY";
    private static final String DEVELOPER_KEY = "YOUR_API_KEY";

    private static final String APPLICATION_NAME = "API code samples";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

    /**
     * Build and return an authorized API client service.
     *
     * @return an authorized API client service
     * @throws GeneralSecurityException, IOException
     */
    public static YouTube getService() throws GeneralSecurityException, IOException {
        final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        return new YouTube.Builder(httpTransport, JSON_FACTORY, null)
            .setApplicationName(APPLICATION_NAME)
            .build();
    }

    /**
     * Call function to create API service object. Define and
     * execute API request. Print API response.
     *
     * @throws GeneralSecurityException, IOException, GoogleJsonResponseException
     */
    public static void main(String[] args)
        throws GeneralSecurityException, IOException, GoogleJsonResponseException {
        YouTube youtubeService = getService();
        
        // Define the Video object, which will be uploaded as the request body.
        Video video = new Video();
        
        // Add the snippet object property to the Video object.
        VideoSnippet snippet = new VideoSnippet();
        snippet.setCategoryId("22");
        snippet.setDescription("Description of uploaded video.");
        snippet.setTitle("Test video upload.");
        video.setSnippet(snippet);
        
        // Add the status object property to the Video object.
        VideoStatus status = new VideoStatus();
        status.setPrivacyStatus("private");
        video.setStatus(status);

        // TODO: For this request to work, you must replace "YOUR_FILE"
        //       with a pointer to the actual file you are uploading.
        //       The maximum file size for this operation is 137438953472.
        File mediaFile = new File("YOUR_FILE");
        InputStreamContent mediaContent =
            new InputStreamContent("application/octet-stream",
                new BufferedInputStream(new FileInputStream(mediaFile)));
        mediaContent.setLength(mediaFile.length());

        // Define and execute the API request
        YouTube.Videos.Insert request = youtubeService.videos()
            .insert("snippet,status", video, mediaContent);
        Video response = request.setKey(DEVELOPER_KEY).execute();
        System.out.println(response);
    }
}

You can also look at another example java code for uploading a video to YouTube on GitHub.

Note that you will need to make a few changes to this:

Under Android, you don't have a main. You will need to (1) put that code whereever you need to and you might want to (2) do it asynchronously.

When using Kotlin, you will also (3) need to modify the syntax accordingly.

Answer from dan1st on Stack Overflow
🌐
GitHub
github.com › youtube › api-samples › blob › master › java › src › main › java › com › google › api › services › samples › youtube › cmdline › data › UploadVideo.java
api-samples/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/UploadVideo.java at master · youtube/api-samples
"Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime()); · // Set the keyword tags that you want to associate with the video. List<String> tags = new ArrayList<String>(); tags.add("test"); tags.add("example"); tags.add("java"); tags.add("YouTube Data API V3"); tags.add("erase me"); snippet.setTags(tags); ·
Author: youtube
🌐
Java Tips
javatips.net › api › com.google.api.services.youtube.model.video
Java Examples for com.google.api.services.youtube.model.Video
The following java examples will help you to understand the usage of com.google.api.services.youtube.model.Video. These source code samples are taken from different open source projects. ... public static Video upload(String url, String playListToken, List<String> tags) { Video uploadedVideo; try { VideoSnippet snippet = new VideoSnippet(); Calendar cal = Calendar.getInstance(); snippet.setTitle("FI-WARE project.
🌐
GitHub
github.com › soumik-dutta › youtube-upload-javaAPI
GitHub - soumik-dutta/youtube-upload-javaAPI: Upload videos with youtube-java API · GitHub
September 27, 2016 - 1.Create an url that will ask the user to give access to the app . 2.After successful authentication a code will be received (An instance of jetty server continuously listens untill the code is received ). 3.Exchange the code just received with ...
Author: soumik-dutta
Top answer
1 of 1
1

This shows how to upload a video using an HTTP request.

There are code snippets that are also available in java (and kotlin is pretty similar).

In order to see how to upload a video, go to https://developers.google.com/youtube/v3/code_samples/code_snippets, select Videos under Resource and insert under method.

If you then click on Show code and select JAVA at the top, you will get this example code:

/**
 * Sample Java code for youtube.videos.insert
 * See instructions for running these code samples locally:
 * https://developers.google.com/explorer-help/guides/code_samples#java
 */

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.InputStreamContent;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;

import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.Video;
import com.google.api.services.youtube.model.VideoSnippet;
import com.google.api.services.youtube.model.VideoStatus;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;

public class ApiExample {
    // You need to set this value for your code to compile.
    // For example: ... DEVELOPER_KEY = "YOUR ACTUAL KEY";
    private static final String DEVELOPER_KEY = "YOUR_API_KEY";

    private static final String APPLICATION_NAME = "API code samples";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

    /**
     * Build and return an authorized API client service.
     *
     * @return an authorized API client service
     * @throws GeneralSecurityException, IOException
     */
    public static YouTube getService() throws GeneralSecurityException, IOException {
        final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        return new YouTube.Builder(httpTransport, JSON_FACTORY, null)
            .setApplicationName(APPLICATION_NAME)
            .build();
    }

    /**
     * Call function to create API service object. Define and
     * execute API request. Print API response.
     *
     * @throws GeneralSecurityException, IOException, GoogleJsonResponseException
     */
    public static void main(String[] args)
        throws GeneralSecurityException, IOException, GoogleJsonResponseException {
        YouTube youtubeService = getService();
        
        // Define the Video object, which will be uploaded as the request body.
        Video video = new Video();
        
        // Add the snippet object property to the Video object.
        VideoSnippet snippet = new VideoSnippet();
        snippet.setCategoryId("22");
        snippet.setDescription("Description of uploaded video.");
        snippet.setTitle("Test video upload.");
        video.setSnippet(snippet);
        
        // Add the status object property to the Video object.
        VideoStatus status = new VideoStatus();
        status.setPrivacyStatus("private");
        video.setStatus(status);

        // TODO: For this request to work, you must replace "YOUR_FILE"
        //       with a pointer to the actual file you are uploading.
        //       The maximum file size for this operation is 137438953472.
        File mediaFile = new File("YOUR_FILE");
        InputStreamContent mediaContent =
            new InputStreamContent("application/octet-stream",
                new BufferedInputStream(new FileInputStream(mediaFile)));
        mediaContent.setLength(mediaFile.length());

        // Define and execute the API request
        YouTube.Videos.Insert request = youtubeService.videos()
            .insert("snippet,status", video, mediaContent);
        Video response = request.setKey(DEVELOPER_KEY).execute();
        System.out.println(response);
    }
}

You can also look at another example java code for uploading a video to YouTube on GitHub.

Note that you will need to make a few changes to this:

Under Android, you don't have a main. You will need to (1) put that code whereever you need to and you might want to (2) do it asynchronously.

When using Kotlin, you will also (3) need to modify the syntax accordingly.

🌐
GitHub
github.com › youtube › api-samples › tree › master › java
api-samples/java at master · youtube/api-samples
Method: youtube.videos.insert Description: This sample calls the API's videos.insert method to upload a video to the channel associated with the request.
🌐
Google
developers.google.com › resources › api-libraries › documentation › youtube › v3 › java › latest › com › google › api › services › youtube › YouTube.Videos.Insert.html
YouTube.Videos.Insert (YouTube Data API v3 (Rev. 222) 1.25.0)
For example, the statistics object encapsulates statistics that YouTube calculates for a video and does not contain values that you can set or modify. If the parameter value specifies a part that does not contain mutable values, that part will still be included in the API response. ... protected Insert(java.lang.String part, Video content, com.google.api.client.http.AbstractInputStreamContent mediaContent) Uploads a video to YouTube and optionally sets the video's metadata.
Top answer
1 of 2
5

did you check the Youtube API on google developers guide, check the Video Upload section? you will find something like this:

VideoEntry newEntry = new VideoEntry();

YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("My Test Movie");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("cars");
mg.getKeywords().addKeyword("funny");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("My description");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));

newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
// alternatively, one could specify just a descriptive string
// newEntry.setLocation("Mountain View, CA");

MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
newEntry.setMediaSource(ms);

String uploadUrl =
  "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";

VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);

Probably you will the successfully authenticate before you can upload teh video like:

YouTubeService service = new YouTubeService(clientID, developer_key);

Hope this helps

2 of 2
1

You have to create a new VideoEntry object

The following code uploads the video:

VideoEntry newEntry = new VideoEntry();

YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("Title goes here");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("keyword-here");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("My description");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));

newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
// alternatively, one could specify just a descriptive string
// newEntry.setLocation("Mountain View, CA");

MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
newEntry.setMediaSource(ms);

String uploadUrl =
"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";

VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);

See https://developers.google.com/youtube/2.0/developers_guide_java#Uploading_Videos

🌐
YouTube
youtube.com › the bargaining market
How to Upload Videos with the YouTube Data API using JAVA, Javascript, Mysql Nowadays - YouTube
This is a quick demonstration about How to Upload Videos with the YouTube Data API using JAVA, Javascript, Mysql these days, if you want the source code cli...
Published: December 29, 2022
Views: 274
Find elsewhere
🌐
DZone
dzone.com › coding › frameworks › youtube data api (v3): introduction with spring boot
YouTube Data API (v3): Introduction With Spring Boot - DZone
September 17, 2019 - YouTube is a video-sharing website where users can view and upload videos. For both web and app development, sometimes we need to access information from YouTube videos. You may also like: Build a Spring Boot API Using Spring Data JPA and Hibernate · In this case, we have to use the API's provided by Google developers. The main goal of this article is to introduce how we can use YoutTube APIs with Java. Here, we will use Spring Boot with Hibernate JPA and libraries from Google to implement the example.
🌐
YouTube
youtube.com › cameron mckenzie
File Upload with Java Example - YouTube
It's easier than ever to upload files with Java. In this example we explore the Servlet and JSP API's @MultipartConfig annotation and how it can be used to a...
Published: September 20, 2020
Views: 12K
🌐
Stack Overflow
stackoverflow.com › questions › 21103048 › upload-video-to-youtube-data-api-v3-without-using-the-java-client-library
Upload video to YouTube Data API v3 without using the Java Client Library - Stack Overflow
January 13, 2014 - Direct upload equivalent of the documentation, would be just setting uploadType=direct. You can set directUploadEnabled to true in this example and see the Post request to make sure. https://github.com/youtube/api-samples/blob/master/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/UploadVideo.java#L136
🌐
Stack Overflow
stackoverflow.com › questions › 40727560 › youtube-api-upload-video-java
google app engine - Youtube API upload video java - Stack Overflow
MediaStreamSource ms = new ... VideoEntry createdEntry = service.insert(new URL("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"), newEntry);...
🌐
YouTube
youtube.com › watch
Upload Video On YouTube Channel Using YouTube API - YouTube
Everybody knows about YouTube. YouTube is the number one video-sharing website in the world. We can use YouTube to host our videos. This saves us a lot of se...
Published: April 19, 2020
🌐
YouTube
youtube.com › watch
Upload a video to YouTube with the YouTube Data API - YouTube
Upload a video to YouTube with the YouTube Data API with ruby on rails.Code: https://github.com/cjavdev/video_automationTwitter: https://twitter.com/cjav_dev...
Published: March 15, 2021
🌐
Stack Overflow
stackoverflow.com › questions › 54431475 › correct-way-to-upload-video-to-youtube-through-api-from-android
java - Correct way to upload video to youtube through API from android - Stack Overflow
i get an example from here and try to adapt these, but i am not sure if is the correct way to do that · P.S. sorry for my bad english... ... You can try the YouTube Direct Lite for Android. "The code is a reference implementation for an Android OS application that captures video, uploads it to YouTube, and submits the video to a YouTube Direct Lite instance".
🌐
YouTube
youtube.com › nemanja tanaskovic
YouTube API Integration in Java: A Complete Guide with Spring Boot - YouTube
Learn how to integrate YouTube API using Java & Spring Boot in this comprehensive tutorial!I'll guide you through every step of creating a Java application t...
Published: January 29, 2024
Views: 758
🌐
Google
developers.google.com › youtube › data api › java quickstart
Java Quickstart | YouTube Data API | Google for Developers
You'll use an API key to retrieve public information about the GoogleDevelopers YouTube channel and OAuth 2.0 credentials to access information about your own YouTube channel. The guide covers how to configure your project, retrieve sample code, replace placeholders with your actual credentials, and execute the Java code to make API calls.
🌐
GeeksforGeeks
geeksforgeeks.org › python › youtube-data-api-for-handling-videos-set-3
Youtube Data API for handling videos | Set-3 - GeeksforGeeks
July 11, 2025 - Select the application type Other, enter the name "YouTube Data API Myvideos", and click the Create button. ... Click on Download button to the right of the client Id to download the JSON file.
🌐
Educative
educative.io › home › courses › integration with youtube data api in javascript › upload videos
Uploading and Setting Thumbnails on YouTube Videos with API
Explore how to upload videos to your YouTube channel using the videos resource insert method and how to set custom thumbnails via the thumbnails set method. Understand the request parameters and response fields involved in these operations to effectively manage your video content with the YouTube Data API.