使用我的网站在youtube上上传视频

时间:2015-01-07 07:20:03

标签: video upload youtube video-processing

我正在创建一个用户上传视频的应用程序,该视频将直接在我帐户的YouTube上上传。

我将如何实现这些目标?

我遇到了问题: -

com.google.gdata.util.InvalidEntryException: Premature end of file.

<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>ParseException</code><internalReason>Premature end of file.</internalReason></error></errors>

以下两行

String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);

我的代码: -

private String uploadYoutube() throws MalformedURLException, IOException, ServiceException {
            String uProjectName = DBConnection.ytprojectName;
            String uName=DBConnection.gmailId;
            String uPassword=DBConnection.gmailPassword;
            String apiKey = DBConnection.ytApi;
            String filename = null;


        YouTubeService service = new YouTubeService(uProjectName, apiKey);
        service.setUserCredentials(uName, uPassword);
        VideoEntry newEntry = new VideoEntry();
        YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
        mg.setTitle(new MediaTitle());


        mg.getTitle().setPlainTextContent(filename);
        mg.setDescription(new MediaDescription());
        mg.getDescription().setPlainTextContent(filename);

        mg.setDescription(new MediaDescription());
        mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Video"));
        mg.setKeywords(new MediaKeywords());
        mg.getKeywords().addKeyword("StudentResumeVideo");

        mg.setPrivate(false);
        mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
        mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
        String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
            VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
            if (createdEntry.isDraft()) {
                YtPublicationState pubState = createdEntry.getPublicationState();

                if (pubState.getState() == YtPublicationState.State.PROCESSING) {
                    String cleanedUrl = createdEntry.getHtmlLink().getHref().replace("/watch?v=", "/embed/");
                    cleanedUrl = cleanedUrl.substring(0, cleanedUrl.indexOf("&feature"));
                    return cleanedUrl;
                } else if (pubState.getState() == YtPublicationState.State.REJECTED) {

                } else if (pubState.getState() == YtPublicationState.State.FAILED) {

                }
            }

        return null;
    }

0 个答案:

没有答案