2015-04-15 58 views
1

如果我打電話谷歌的API-Java的客戶端:setForMine(true),當invalidSearchFilter錯誤

YouTube.Search.List.setForMine(true); 

然後我得到即使所要求的使用YouTube.Search.List.setForMine(true)YouTube.Search.List.setType("video")也被稱爲以下錯誤:

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過濾標籤(關鍵字)來列出我自己的「不公開」視頻?

在此先感謝。

回答

0

我發現了這個問題。我未能將適當的憑據對象傳遞給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(); 

不過,我覺得這個錯誤信息會讓人誤解。

+0

您是否可以在搜索查詢中添加標籤過濾器?如果是的話,你的查詢參數語法是什麼? – kjosh

相關問題