【问题标题】:google-api-java-client: setForMine(true) causes invalidSearchFilter errorgoogle-api-java-client: setForMine(true) 导致 invalidSearchFilter 错误
【发布时间】:2015-04-15 15:51:32
【问题描述】:

如果我打电话

YouTube.Search.List.setForMine(true);

然后我得到以下错误,即使 YouTube.Search.List.setType("video") 也根据使用 YouTube.Search.List.setForMine(true) 的要求被调用:

There was a service error: 400 : Invalid combination of search filters and/or restrictions.
hu.pocketguide.kmlvideo.youtube.exception.YouTubeException: Service error.
    at com.google.api.services.samples.youtube.cmdline.data.PgFindByKmlId.findVideosByKmlId(PgFindByKmlId.java:107)
    at com.google.api.services.samples.youtube.cmdline.data.PgFindByKmlId.main(PgFindByKmlId.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "youtube.search",
    "location" : "",
    "locationType" : "parameter",
    "message" : "Invalid combination of search filters and/or restrictions.",
    "reason" : "invalidSearchFilter"
  } ],
  "message" : "Invalid combination of search filters and/or restrictions."
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1049)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
    at com.google.api.services.samples.youtube.cmdline.data.PgFindByKmlId.findVideosByKmlId(PgFindByKmlId.java:100)
    ... 7 more

Try it! 中的相同查询! https://developers.google.com/youtube/v3/docs/search/list 的部分工作。

谁能告诉我如何使用 google-api-java-client 过滤标签(关键字)来列出我自己的“未列出”视频?

提前致谢。

【问题讨论】:

    标签: java youtube google-api-java-client


    【解决方案1】:

    我发现了问题。我未能将适当的 Credential 对象传递给 new YouTube.Builder(...)。通过以下初始化,它可以工作:

    List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.readonly");
    Credential credential = Auth.authorize(scopes, "mycredentialdatastore");
                youtube = new YouTube.Builder(
                        Auth.HTTP_TRANSPORT,
                        Auth.JSON_FACTORY,
                        credential).setApplicationName("mysample").build();
    

    不过,我发现错误消息具有误导性。

    【讨论】:

    • 您是否能够为搜索查询中的标签添加过滤器?如果是,您的查询参数语法是什么?
    猜你喜欢
    • 2011-08-31
    • 1970-01-01
    • 2017-07-30
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2011-05-09
    相关资源
    最近更新 更多