如何在java中使用v3 Data Api插入YouTube频道横幅?

时间:2015-04-03 11:13:25

标签: java youtube

ChannelBannerResource chBannerResource = new ChannelBannerResource();
chBannerResource.setKind("youtube#channelBannerResource");
chBannerResource.setEtag("JcMoTLb1iDZi7UYDRZDsYNLPWNA/X7zrV-CaEaRAq1KbyVYs4KQu6MU");                chBannerResource.setUrl("http://myimage.com/ram/channelbaner.jpg");
YouTube.ChannelBanners.Insert  chbannerresponse  = youtube.channelBanners().insert(chBannerResource);ChannelBannerResource res= chbannerresponse.execute(); 

    Error :- GoogleJsonResponseException code: 400 : contentDetails
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "youtube.part",
    "location" : "part",
    "locationType" : "parameter",
    "message" : "contentDetails",
    "reason" : "unexpectedPart"
  } ],
  "message" : "contentDetails"
}

请帮帮我..........

1 个答案:

答案 0 :(得分:0)

Channel myChannel = channelListResponse.getItems().get(0);
        String channelId = myChannel.getId();
        System.out.println("channel id===" + channelId);
        URL url = new URL(imageurl248X1152);
        URLConnection conn = url.openConnection();
        InputStreamContent mediaContent = new InputStreamContent(
                "image/jpeg", conn.getInputStream());
        ChannelBannerResource chBannerResource = new ChannelBannerResource();
        YouTube.ChannelBanners.Insert chbannerresponse = youtube
                .channelBanners().insert(chBannerResource, mediaContent);
        ChannelBannerResource res = chbannerresponse.execute();
        System.out.println("res====" + res.getUrl());
        ChannelBrandingSettings channelBrandingSettings = new ChannelBrandingSettings();
        ChannelSettings channelSettings = new ChannelSettings();
        channelSettings.setDescription(des);
        channelSettings.setKeywords(keyword);
        channelSettings.setProfileColor(profilecolor);
        ImageSettings imageSettings = new ImageSettings();
        imageSettings.setBannerExternalUrl(res.getUrl());
        channelBrandingSettings.setChannel(channelSettings).setImage(
                imageSettings);
        Channel channel = new Channel();
        channel.setId(channelId);
        channel.setBrandingSettings(channelBrandingSettings);
        System.out.println("channel===" + channel);
        Channel updateChannelResponse = youtube.channels()
                .update("brandingSettings", channel).execute();