>我正在尝试访问YouTube数据API,但此示例代码似乎不起作用。
我的 gradle 构建文件如下:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev79-1.17.0-rc'
compile 'com.google.api.client:google-api-client-googleapis:1.4.0-alpha'
}
我尝试使用的一个最小测试用例是:
YouTube youtube = new YouTube.Builder(new NetHttpTransport(), new GsonFactory(), new HttpRequestInitializer() {
@Override
public void initialize(com.google.api.client.http.HttpRequest httpRequest) throws IOException {}
}).setApplicationName("youtube-api").build();
YouTube.Search.List search = youtube.search().list("id");
search.setKey(API_KEY);
search.setQ("search string");
search.execute(); // execute() method does not exist
显然我引用了错误版本的google-api-client库。正确的 gradle 构建脚本是:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev79-1.17.0-rc'
compile 'com.google.api-client:google-api-client:1.17.0-rc'
compile 'com.google.http-client:google-http-client-gson:1.17.0-rc'
}