使用youtube java客户端库api在youtube上上传视频

发布于 2024-12-05 07:44:59 字数 2441 浏览 1 评论 0原文

以下是错误:

抱歉,您的上传无效:

<?xml version='1.0' encoding='UTF-8'?>
<errors>
<error>
<domain>yt:validation</domain>
<code>invalid_value</code>
<locationtype='xpath'>media:group/media:category[@scheme='http://gdata.youtube.com/schemas/2007/categories.cat']/text()</location>
</error>
</errors>

以下是我的视频上传代码:

public class YtUpload {

        public YtUpload() {

        try {

        String client_id = "abcd";
        String developer_key = "AI39si6Nb_onkYi1b7...";
    YouTubeService service = new YouTubeService(client_id,developer_key);
    service.setUserCredentials("[email protected]", "password");
    VideoEntry newEntry = new VideoEntry();

        YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
    mg.setTitle(new MediaTitle());
    mg.getTitle().setPlainTextContent("My Test Game");
    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "tech"));
    mg.setKeywords(new MediaKeywords());
    mg.getKeywords().addKeyword("conference");
    mg.setDescription(new MediaDescription());
    mg.getDescription().setPlainTextContent("My description");
    mg.setPrivate(false);
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));

    newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
    //alternatively, one could specify just a descriptive string
    newEntry.setLocation("Mountain View, CA");

        MediaFileSource ms = new MediaFileSource(new File("c:\\largeV_smallA.mp4"), "video/quicktime");
    newEntry.setMediaSource(ms);
    String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
    service.insert(new URL(uploadUrl), newEntry);
    } 
        catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
            e.printStackTrace();
    } catch (ServiceException se) {
        System.out.println("Sorry, your upload was invalid:");
        System.out.println(se.getResponseBody());
        return;
    }
    System.out.println("Video uploaded successfully!");
    }

    public static void main(String[] args) {
        new YtUpload();
    }}

Following is the error:

Sorry, your upload was invalid:

<?xml version='1.0' encoding='UTF-8'?>
<errors>
<error>
<domain>yt:validation</domain>
<code>invalid_value</code>
<locationtype='xpath'>media:group/media:category[@scheme='http://gdata.youtube.com/schemas/2007/categories.cat']/text()</location>
</error>
</errors>

Below is my code for video-upload:

public class YtUpload {

        public YtUpload() {

        try {

        String client_id = "abcd";
        String developer_key = "AI39si6Nb_onkYi1b7...";
    YouTubeService service = new YouTubeService(client_id,developer_key);
    service.setUserCredentials("[email protected]", "password");
    VideoEntry newEntry = new VideoEntry();

        YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
    mg.setTitle(new MediaTitle());
    mg.getTitle().setPlainTextContent("My Test Game");
    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "tech"));
    mg.setKeywords(new MediaKeywords());
    mg.getKeywords().addKeyword("conference");
    mg.setDescription(new MediaDescription());
    mg.getDescription().setPlainTextContent("My description");
    mg.setPrivate(false);
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));

    newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
    //alternatively, one could specify just a descriptive string
    newEntry.setLocation("Mountain View, CA");

        MediaFileSource ms = new MediaFileSource(new File("c:\\largeV_smallA.mp4"), "video/quicktime");
    newEntry.setMediaSource(ms);
    String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
    service.insert(new URL(uploadUrl), newEntry);
    } 
        catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
            e.printStackTrace();
    } catch (ServiceException se) {
        System.out.println("Sorry, your upload was invalid:");
        System.out.println(se.getResponseBody());
        return;
    }
    System.out.println("Video uploaded successfully!");
    }

    public static void main(String[] args) {
        new YtUpload();
    }}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

書生途 2024-12-12 07:44:59
MediaFileSource(new File("c:\\largeV_smallA.**mp4**"), "video/**quicktime**");

mp4 和 Quicktime 不匹配

MediaFileSource(new File("c:\\largeV_smallA.**mp4**"), "video/**quicktime**");

mp4 and quicktime not match

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文