Youtube错误400缺少prams api v3

时间:2015-10-23 16:35:04

标签: java youtube youtube-api

我发送以下请求,我得到error 400 missing params但是当我通过GET手动发送请求时,它可以正常工作:

try {
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest arg0) throws IOException {}
        }).setApplicationName("youtube-cmdline-myuploads-sample").build();

        YouTube.Channels.List channelRequest = youtube.channels().list("id,snippet");
        channelRequest.setKey("key");
        //channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo");
        channelRequest.set("channelId", "UC-9-kyTW8ZkZNDHQJ6FgpwQ");
        System.out.println(channelRequest.toString());
        ChannelListResponse channelResult = channelRequest.execute(); //error here
        List<Channel> channelsList = channelResult.getItems();
...

但是由于某种原因,这有效:

https://www.googleapis.com/youtube/v3/search?key=key&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&part=snippet,id&order=date&maxResults=20

更详细的错误:

    {
  "code" : 400,
  "errors" : [ {
    "domain" : "youtube.parameter",
    "location" : "",
    "locationType" : "parameter",
    "message" : "No filter selected.",
    "reason" : "missingRequiredParameter"
  } ],
  "message" : "No filter selected."
}

2 个答案:

答案 0 :(得分:0)

您使用的是错误的课程。它不是一个频道,它是根据您提到的工作网址的搜索列表。

YouTube.Search.List searchRequest = youtube.search().list("id,snippet");

答案 1 :(得分:0)

你可以这样试试:

try {
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest arg0) throws IOException {}
        }).setApplicationName("youtube-cmdline-myuploads-sample").build();

        YouTube.Channels.List channelRequest = youtube.channels().list("id,snippet");
        channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo");
        channelRequest.setId("UC-9-kyTW8ZkZNDHQJ6FgpwQ");

        // probably needed:
        // channelRequest.setMine(true);
        // or
        // channelRequest.setForUsername("userwithaccess");

        System.out.println(channelRequest.toString());
        ChannelListResponse channelResult = channelRequest.execute(); //error here
        List<Channel> channelsList = channelResult.getItems();

请参阅此文档:https://developers.google.com/resources/api-libraries/documentation/youtube/v3/java/latest/com/google/api/services/youtube/YouTube.Channels.List.html#setId%28java.lang.String%29

请注意上述评论,因为我目前正在限制...setMine(true); ...