我正在尝试将字幕上传到我的YouTube视频,但它失败了。请帮忙。感谢。
我的代码:
{
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account and requires requests to use an SSL connection.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
// Authorize the request.
Credential credential = Auth.authorize(scopes, "captions");
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
.setApplicationName("youtube-cmdline-captions-sample").build();
Caption captionObjectDefiningMetadata = new Caption();
CaptionSnippet snippet = new CaptionSnippet();
snippet.setVideoId(videoId);
snippet.setLanguage("en");
snippet.setName("caption");
snippet.setIsAutoSynced(true);
captionObjectDefiningMetadata.setSnippet(snippet);
InputStreamContent mediaContent = new InputStreamContent(
CAPTION_FILE_FORMAT,
new BufferedInputStream(new FileInputStream(captionFile)));
mediaContent.setLength(captionFile.length());
Insert captionInsert = youtube.captions().insert("snippet",
captionObjectDefiningMetadata, mediaContent);
MediaHttpUploader uploader = captionInsert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
// Upload the caption track.
Caption uploadedCaption = captionInsert.execute();
}
我的错误:
GoogleJsonResponseException code: 400 : The request contains invalid metadata values, which prevent the track from being created. Confirm that the request specifies valid values for the <code>snippet.language</code>, <code>snippet.name</code>, and <code>snippet.videoId</code> properties. The <code>snippet.isDraft</code> property can also be included, but it is not required.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "youtube.caption",
"location" : "body.snippet",
"locationType" : "other",
"message" : "The request contains invalid metadata values, which prevent the track from being created. Confirm that the request specifies valid values for the <code>snippet.language</code>, <code>snippet.name</code>, and <code>snippet.videoId</code> properties. The <code>snippet.isDraft</code> property can also be included, but it is not required.",
"reason" : "invalidMetadata"
} ],
"message" : "The request contains invalid metadata values, which prevent the track from being created. Confirm that the request specifies valid values for the <code>snippet.language</code>, <code>snippet.name</code>, and <code>snippet.videoId</code> properties. The <code>snippet.isDraft</code> property can also be included, but it is not required."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at UploadVideo.uploadCaption(UploadVideo.java:358)
at UploadVideo.main(UploadVideo.java:214)
我注意到如果删除setIsAutoSync行,它会上传,但不会自动同步我的字幕。任何帮助是极大的赞赏。感谢。
答案 0 :(得分:0)
您不应该设置'isAutoSync'选项,尝试设置'sync'选项。 它对我有用。 或者只是在插入标题后更新标题。