Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Youtube Upload: 401 Unauthorized

$
0
0

Ive copied the example from Google to upload a video. (https://developers.google.com/youtube/v3/code_samples/code_snippets?hl=de&apix=true)

After i copied this code, I created an api-key on their console.

   public class ApiExample {    private static final String DEVELOPER_KEY = "AIzaSyAPz-xxxxxxxxxxxxxaA";    private static final String APPLICATION_NAME = "javauploadtoyoutube";    private static final String FILE_PATH_NAME = "C:\\PATH\\downloaded_video.mp4";    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("42");        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("public");        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 274877906944.        File mediaFile = new File(FILE_PATH_NAME);        InputStreamContent mediaContent =                new InputStreamContent("video/mp4",                        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);    }}

Now im trying to start the program and the error appears. I watched other questions too. There they told the questioner to use the oauth2 access_token. I assumed theyre meaning the client_secrets token. I replaced it into the DEVELOPER_KEY variable, but it didnt work too. (Error "401 Unauthorized" to upload video in my youtube account with Simple Access API (API Key))

This is my error message:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>