缺少YouTube Data API中的execute()方法

时间:2013-10-16 19:41:13

标签: java youtube-api

我正在尝试访问YouTube数据API,但this sample code似乎无效。

我的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

1 个答案:

答案 0 :(得分:1)

显然我引用了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'
}