Java Google Youtube API данных :: Несанкционированный - PullRequest
0 голосов
/ 21 ноября 2011

Я хотел загрузить видео на YouTube, используя Java Google Data API. Я получил следующий код из документации Google Data Api для загрузки видео. Единственное, что мне нужно изменить в этом коде - это идентификатор клиента и ключ Porduct. я использую метод followinf для аутентификации

Сервис YouTubeService = новый YouTubeService (clientID, developer_key);

Ключ клиента - это мой идентификатор электронной почты Google, пробовал с помощью wasy,

  • только при условии Имя пользователя e, g. "Sampleuser"
  • или полный идентификатор Gmail, например, "sampleuser@gmail.com" или "smapleuser@googlemail.com"

Я получил ключ разработчика, зарегистрировав свой почтовый идентификатор Google как упомянуто "smapleuser@googlemail.com"

но я всегда получаю следующее исключение

com.google.gdata.util.AuthenticationException: Unauthorized
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.media.MediaService.insert(MediaService.java:400)
at YouTube.videoUpload(YouTube.java:115)
at YouTube.main(YouTube.java:43)

вот мой код для видео Загрузить

YouTubeService service = new YouTubeService("sampleuser@gmail.com",
            "fakegoogleapplicationidjsuttoshowthatimgivingidhere");
    // YouTubeService service = new YouTubeService("My Application");
    VideoEntry newEntry = new VideoEntry();

    YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
    mg.setTitle(new MediaTitle());
    mg.getTitle().setPlainTextContent("My Test Movie");
    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
    mg.setKeywords(new MediaKeywords());
    mg.getKeywords().addKeyword("cars");
    mg.getKeywords().addKeyword("funny");
    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("D:\\maths.mp4")
    , "video/quicktime");
    newEntry.setMediaSource(ms);

    // "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
    String uploadUrl =
        "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";

    try {
        VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

помогите, не можете найти решение. большое спасибо .. ищу ответ

1 Ответ

0 голосов
/ 02 декабря 2011

Попробуйте добавить

service.setUserCredentials("email_here", "password_here");

...