我是一名初级开发者,想要开始使用 Google Cloud。
我刚刚在 GCP 上创建了一个项目。
我根据 https://developers.google.com/zero-touch/guides/customer/quickstart/java-service-account
上的指南将服务帐户 JSON 与我的项目集成我尝试将本地文件系统中的视频插入 Youtube,但出现超出配额错误,并且在此之前我无法成功上传小于 2mb 的简单视频,因为我一直在尝试。
附上截图和代码片段
我的代码片段
String localFilePath = "/home/ubuntu/video.mp4";
FileContent videoContent = new FileContent("video/*", new File(localFilePath));
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
YouTube youTube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpCredentialsAdapter(getServiceCredential()))
.setApplicationName("Game")
.build();
YouTube.Videos.Insert videoInsert = youTube.videos()
.insert(Collections.singletonList("snippet,statistics,status"), videoMetadata, videoContent);
private InputStream getCredentialInputStream() throws IOException {
InputStream in = YouTubeService.class.getResourceAsStream(CREDENTIAL_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: ".concat(CREDENTIAL_PATH));
}
return in;
}
private GoogleCredentials getServiceCredential() throws IOException {
GoogleCredentials credentials = ServiceAccountCredentials.fromStream(
Objects.requireNonNull(getCredentialInputStream()))
.createScoped(SCOPES);
return credentials;
}
作为对您的问题的参考,根据上一篇文章中的markus,需要满足一个要求,除了配额错误之外,这可能有助于解决您的担忧。可能是您尚未设置 Youtube 帐户或尚未设置 Youtube 频道来上传视频。