I’m having trouble uploading videos to YouTube using their API and keep running into authentication issues. The error message says I need a developer key but I’m not sure what I’m doing wrong.
public class VideoUploader {
private static final String DEV_KEY = "my-developer-key-here";
private static final String USERNAME = "my_username";
private static final String PASSWORD = "my_password";
public void uploadToYouTube() throws Exception {
YouTubeService ytService = new YouTubeService("MyApp", DEV_KEY);
try {
ytService.setUserCredentials(USERNAME, PASSWORD);
} catch (AuthenticationException ex) {
System.out.println("Login failed");
return;
}
VideoEntry video = new VideoEntry();
YouTubeMediaGroup mediaGroup = video.getOrCreateMediaGroup();
mediaGroup.setTitle(new MediaTitle());
mediaGroup.getTitle().setPlainTextContent("Sample Video Title");
mediaGroup.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Entertainment"));
mediaGroup.setDescription(new MediaDescription());
mediaGroup.getDescription().setPlainTextContent("Video description here");
MediaFileSource fileSource = new MediaFileSource(new File("myvideo.mp4"), "video/mp4");
video.setMediaSource(fileSource);
String uploadEndpoint = "https://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry uploadedVideo = ytService.insert(new URL(uploadEndpoint), video);
System.out.println("Video uploaded successfully");
}
}
The error I get is:
com.google.gdata.util.ServiceForbiddenException: Developer key required for this operation
I have a valid API key but it seems like it’s not being recognized properly. Do I need to register my application somewhere or enable specific permissions? Any guidance would be helpful since the Google documentation wasn’t clear about this part.