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

Unable to set YouTube Video Title Programmatically using Java (Getting 500 and 405 Errors)

$
0
0

I'm working on a project where I'm utilizing the YouTube API v3 through Cloud Console using Java to update video titles programmatically. Despite successfully retrieving video properties like number of views, likes, comments and getting the youtube video title, I'm encountering consistent **500 **Internal Server Error or sometimes **405 **Method Not Allowed errors when attempting to update the video title using a PUT request.The YouTube account from which the video was originally uploaded and the Google account associated with the API key being used for this project are indeed the same.Here's the error code I'm encountering:

errorException in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server ErrorGET https://www.googleapis.com/youtube/v3/videos?id=VidID&key=APIKey&part=snippet,statistics{"code" : 500,"errors" : [ {"domain" : "global","message" : "Internal error encountered.","reason" : "backendError"  } ],"message" : "Internal error encountered.","status" : "INTERNAL"}    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:118)    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:37)    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:428)    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1108)    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:514)    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:455)    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:565)    at com.YoutubeLikesCounter.demo.YLCmain.main(YLCmain.java:40) 

And my Java code is

Java      JsonFactory jsonFactory = new JacksonFactory();        YouTube youtube = new YouTube.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, request -> {            request.setParser(new JsonObjectParser(jsonFactory));        }).setApplicationName(APPLICATION_NAME).build();        // Define the new title        String newTitle = "This Title is set by Java";        // Retrieve video information and statistics        YouTube.Videos.List videoListRequest = youtube.videos().list("snippet,statistics").setId(VIDEO_ID)                .setKey(API_KEY);        com.google.api.services.youtube.model.VideoListResponse videoListResponse = videoListRequest.execute();        List<Video> videos = videoListResponse.getItems();        if (!videos.isEmpty()) {            Video video = videos.get(0);            VideoSnippet snippet = video.getSnippet();            System.out.println(snippet.getTitle().toString());            snippet.setTitle(newTitle);            video.setSnippet(snippet);            Video updatedVideo = youtube.videos().update("snippet", video).execute();            System.out.println("Video title updated: " + updatedVideo.getSnippet().getTitle());            // Get the view and comment count            VideoStatistics stats = video.getStatistics();            BigInteger viewCount = stats.getViewCount();            BigInteger commentCount = stats.getCommentCount();            System.out.println("Number of views: " + viewCount);            System.out.println("Number of comments: " + commentCount);

When I commented the code to set the title of video i am successfully able to get the current title and other metadata of video. I guess there is some issue with the permission on the google cloud console but as of my knowledge I checked everything on Google Cloud Console and gave all the necessary permissions.I have also opened this issue on Github


Viewing all articles
Browse latest Browse all 3832

Trending Articles



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