Java 如何让Youtube API自动同步我的视频标题?
我正试图上传字幕到我的youtube视频,但失败了。请帮忙。谢谢 我的代码:Java 如何让Youtube API自动同步我的视频标题?,java,api,youtube,caption,Java,Api,Youtube,Caption,我正试图上传字幕到我的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.newArrayLi
{
// 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();
}
我注意到,如果我删除setIsAutoSync行,它将上载,但它不会自动同步我的标题。非常感谢您的帮助。谢谢。您不应该设置“自动同步”选项,请尝试设置“同步”选项。 这对我有用。 或者在插入标题后更新标题
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)